zap

package
v0.0.66 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init() error

Init will initial global *zap.Logger according to Server/Client configurations. log file default to config.Server.LoggerConfig.LogFile or config.Client.LoggerConfig.LogFile.

func NewGin

func NewGin(filename ...string) *zap.Logger

NewGin returns a *Logger instance that contains *zap.Logger. The difference between NewGin and New is disable fields "caller", "level" and "msg".

func NewStdLog

func NewStdLog() *log.Logger

NewStdLog

func NewSugared

func NewSugared(filename ...string) *zap.SugaredLogger

NewSugared new a *zap.SugaredLogger instance according to Server/Client configurations. The instance implements types.Logger and types.StructuredLogger interface. log file default to config.Server.LoggerConfig.LogFile or config.Client.LoggerConfig.LogFile, you can create a custom *zap.SugaredLogger by pass log filename to this function.

func NewZap

func NewZap(filename ...string) *zap.Logger

NewZap new a *zap.Logger instance according to Server/Client configurations. The instance implements types.Logger interface. log file default to config.Server.LoggerConfig.LogFile or config.Client.LoggerConfig.LogFile, you can create a custom *zap.Logger by pass log filename to this function.

Types

type GormLogger

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

GormLogger implements gorm logger.Interface https://github.com/moul/zapgorm2 may be the alternative choice. eg: gorm.Open(mysql.Open(dsnAsset), &gorm.Config{Logger: zapgorm2.New(pkgzap.NewZap("./logs/gorm_asset.log"))})

func NewGorm

func NewGorm(filename ...string) *GormLogger

NewGorm returns a *GormLogger instance that implements gorm logger.Interface. The difference between NewGorm and NewLogger is the `zap.AddCallerSkip()`

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. https://github.com/moul/zapgorm2 may be the alternative choice. eg: gorm.Open(mysql.Open(dsnAsset), &gorm.Config{Logger: zapgorm2.New(pkgzap.NewZap("./logs/gorm_asset.log"))})

func New

func New(filename ...string) *Logger

New returns *Logger instance that contains *zap.Logger and *zap.SugaredLogger and implements types.Logger.

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, keysAndValues ...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, keysAndValues ...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, keysAndValues ...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, keysAndValues ...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, keysAndValues ...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 one or multiple fields. Examples:

log := logger.Controller.

With(types.PHASE, string(types.PHASE_UPDATE)).
With(types.CTX_USERNAME, c.GetString(types.CTX_USERNAME)).
With(types.CTX_USER_ID, c.GetString(types.CTX_USER_ID)).
With(types.REQUEST_ID, c.GetString(types.REQUEST_ID))

log := logger.Controller.With(

types.PHASE, string(types.PHASE_DELETE),
types.CTX_USERNAME, c.GetString(types.CTX_USERNAME),
types.CTX_USER_ID, c.GetString(types.CTX_USER_ID),
types.REQUEST_ID, c.GetString(types.REQUEST_ID),
)

Jump to

Keyboard shortcuts

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