zap

package
v0.10.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean()

func Init

func Init() error

Init initializes global loggers from config and wires subsystem loggers. Returns error on configuration or initialization failure.

func NewCasbin

func NewCasbin(filename string) casbinl.Logger

NewCasbin builds a casbin Logger (no caller field). filename: target log file name ("/dev/stdout" for console)

func NewGin

func NewGin(filename string) *zap.Logger

NewGin builds a *zap.Logger for Gin access logs. filename: target log file name ("/dev/stdout" for console)

func NewGorm

func NewGorm(filename string) gorml.Interface

NewGorm builds a gorm logger.Interface. filename: target log file name ("/dev/stdout" for console)

func NewStdLog

func NewStdLog() *log.Logger

NewStdLog builds a *log.Logger backed by *zap.Logger.

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

func NewZap

func NewZap(filename string, opts ...Option) *zap.Logger

NewZap builds a *zap.Logger 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

func (*GormLogger) Error

func (g *GormLogger) Error(_ context.Context, str string, args ...any)

func (*GormLogger) Info

func (g *GormLogger) Info(_ context.Context, str string, args ...any)

func (*GormLogger) LogMode

func (g *GormLogger) LogMode(gorml.LogLevel) gorml.Interface

func (*GormLogger) Trace

func (g *GormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*GormLogger) Warn

func (g *GormLogger) Warn(_ context.Context, str string, args ...any)

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger implements types.Logger interface.

func New

func New(filename string, opts ...Option) *Logger

New builds a types.Logger backed by *zap.Logger. filename: target log file name ("/dev/stdout" for console) opts: optional encoder options

func (*Logger) Debug

func (l *Logger) Debug(args ...any)

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...any)

func (*Logger) Debugw

func (l *Logger) Debugw(msg string, keysValues ...any)

func (*Logger) Debugz

func (l *Logger) Debugz(msg string, fields ...zap.Field)

func (*Logger) Error

func (l *Logger) Error(args ...any)

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...any)

func (*Logger) Errorw

func (l *Logger) Errorw(msg string, keysValues ...any)

func (*Logger) Errorz

func (l *Logger) Errorz(msg string, fields ...zap.Field)

func (*Logger) Fatal

func (l *Logger) Fatal(args ...any)

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...any)

func (*Logger) Fatalw

func (l *Logger) Fatalw(msg string, keysValues ...any)

func (*Logger) Fatalz

func (l *Logger) Fatalz(msg string, fields ...zap.Field)

func (*Logger) Info

func (l *Logger) Info(args ...any)

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...any)

func (*Logger) Infow

func (l *Logger) Infow(msg string, keysValues ...any)

func (*Logger) Infoz

func (l *Logger) Infoz(msg string, fields ...zap.Field)

func (*Logger) Warn

func (l *Logger) Warn(args ...any)

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...any)

func (*Logger) Warnw

func (l *Logger) Warnw(msg string, keysValues ...any)

func (*Logger) Warnz

func (l *Logger) Warnz(msg string, fields ...zap.Field)

func (*Logger) With

func (l *Logger) With(fields ...string) types.Logger

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) WithArray

func (l *Logger) WithArray(name string, arr zapcore.ArrayMarshaler) types.Logger

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 (l *Logger) WithObject(name string, obj zapcore.ObjectMarshaler) types.Logger

func (*Logger) WithServiceContext

func (l *Logger) WithServiceContext(ctx *types.ServiceContext, phase consts.Phase) types.Logger

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)

func (*Logger) ZapLogger

func (l *Logger) ZapLogger() *zap.Logger

type Option added in v0.10.0

type Option struct {
	DisableMsg    bool
	DisableLevel  bool
	DisableCaller bool
	TSLayout      string
}

Option configures encoder behavior for constructors. DisableMsg/DisableLevel hide "msg" and "level" fields; TSLayout sets time format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址