Documentation
¶
Index ¶
- func Clean()
- func Init() error
- func NewCasbin(filename string) casbinl.Logger
- func NewGin(filename string) *zap.Logger
- func NewGorm(filename string) gorml.Interface
- func NewStdLog() *log.Logger
- func NewSugared(filename string, opts ...Option) *zap.SugaredLogger
- func NewZap(filename string, opts ...Option) *zap.Logger
- type CasbinLogger
- type GormLogger
- func (g *GormLogger) Error(_ context.Context, str string, args ...any)
- func (g *GormLogger) Info(_ context.Context, str string, args ...any)
- func (g *GormLogger) LogMode(gorml.LogLevel) gorml.Interface
- func (g *GormLogger) Trace(ctx context.Context, begin time.Time, ...)
- func (g *GormLogger) Warn(_ context.Context, str string, args ...any)
- type Logger
- func (l *Logger) Debug(args ...any)
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Debugw(msg string, keysValues ...any)
- func (l *Logger) Debugz(msg string, fields ...zap.Field)
- func (l *Logger) Error(args ...any)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Errorw(msg string, keysValues ...any)
- func (l *Logger) Errorz(msg string, fields ...zap.Field)
- func (l *Logger) Fatal(args ...any)
- func (l *Logger) Fatalf(format string, args ...any)
- func (l *Logger) Fatalw(msg string, keysValues ...any)
- func (l *Logger) Fatalz(msg string, fields ...zap.Field)
- func (l *Logger) Info(args ...any)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) Infow(msg string, keysValues ...any)
- func (l *Logger) Infoz(msg string, fields ...zap.Field)
- func (l *Logger) Warn(args ...any)
- func (l *Logger) Warnf(format string, args ...any)
- func (l *Logger) Warnw(msg string, keysValues ...any)
- func (l *Logger) Warnz(msg string, fields ...zap.Field)
- func (l *Logger) With(fields ...string) types.Logger
- func (l *Logger) WithArray(name string, arr zapcore.ArrayMarshaler) types.Logger
- func (l *Logger) WithControllerContext(ctx *types.ControllerContext, phase consts.Phase) types.Logger
- func (l *Logger) WithDatabaseContext(ctx *types.DatabaseContext, phase consts.Phase) (clone types.Logger)
- func (l *Logger) WithObject(name string, obj zapcore.ObjectMarshaler) types.Logger
- func (l *Logger) WithServiceContext(ctx *types.ServiceContext, phase consts.Phase) types.Logger
- func (l *Logger) ZapLogger() *zap.Logger
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init() error
Init initializes global loggers from config and wires subsystem loggers. Returns error on configuration or initialization failure.
func NewCasbin ¶
NewCasbin builds a casbin Logger (no caller field). filename: target log file name ("/dev/stdout" for console)
func NewGin ¶
NewGin builds a *zap.Logger for Gin access logs. filename: target log file name ("/dev/stdout" for console)
func NewGorm ¶
NewGorm builds a gorm logger.Interface. filename: target log file name ("/dev/stdout" for console)
func NewSugared ¶
func NewSugared(filename string, opts ...Option) *zap.SugaredLogger
NewSugared builds a *zap.SugaredLogger with optional filename and options. filename: target log file name ("/dev/stdout" for console) opts: optional encoder options
Types ¶
type CasbinLogger ¶
type CasbinLogger struct {
// contains filtered or unexported fields
}
func (*CasbinLogger) OnAfterEvent ¶ added in v0.10.14
func (c *CasbinLogger) OnAfterEvent(entry *casbinl.LogEntry) error
func (*CasbinLogger) OnBeforeEvent ¶ added in v0.10.14
func (c *CasbinLogger) OnBeforeEvent(entry *casbinl.LogEntry) error
func (*CasbinLogger) SetEventTypes ¶ added in v0.10.14
func (c *CasbinLogger) SetEventTypes(eventTypes []casbinl.EventType) error
func (*CasbinLogger) SetLogCallback ¶ added in v0.10.14
func (c *CasbinLogger) SetLogCallback(callback func(entry *casbinl.LogEntry) error) error
type GormLogger ¶
type GormLogger struct {
// contains filtered or unexported fields
}
GormLogger implements gorm logger.Interface
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger implements types.Logger interface.
func New ¶
New builds a types.Logger backed by *zap.Logger. filename: target log file name ("/dev/stdout" for console) opts: optional encoder options
func (*Logger) With ¶
With creates a new logger with additional string key-value pairs. Each pair of arguments must be a key(string) followed by its value(string). If an odd number of arguments is provided, an empty string will be appended as the last value.
Example 1 - Multiple With calls:
logger.With("phase", "update").
With("user", "admin").
With("request_id", "123")
Example 2 - Single With call with multiple fields:
logger.With(
"phase", "update",
"user", "admin",
"request_id", "123",
)
Returns the original logger if no fields are provided or if only an empty key is provided.
func (*Logger) WithControllerContext ¶
func (l *Logger) WithControllerContext(ctx *types.ControllerContext, phase consts.Phase) types.Logger
WithControllerContext creates a new logger with controller context fields. It extends the base logger with phase, username, user ID, and request ID from *types.ControllerContext.
examples:
log := logger.Controller.WithControllerContext(ctx, consts.PHASE_LIST)
func (*Logger) WithDatabaseContext ¶
func (l *Logger) WithDatabaseContext(ctx *types.DatabaseContext, phase consts.Phase) (clone types.Logger)
WithDatabaseContext creates a new logger with database context fields. It extends the base logger with phase, username, user ID, and request ID from *types.DatabaseContext.
examples:
log := logger.Database.WithDatabaseContext(ctx, consts.PHASE_LIST_BEFORE)
func (*Logger) WithObject ¶
func (*Logger) WithServiceContext ¶
WithServiceContext creates a new logger with service context fields. It extends the base logger with phase, username, user ID, and request ID from *types.ServiceContext.
examples:
log := logger.Service.WithServiceContext(ctx, consts.PHASE_LIST_BEFORE)