Documentation ¶
Index ¶
- func Init() error
- func NewGin(filename ...string) *zap.Logger
- func NewStdLog() *log.Logger
- func NewSugared(filename ...string) *zap.SugaredLogger
- func NewZap(filename ...string) *zap.Logger
- 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, keysAndValues ...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, keysAndValues ...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, keysAndValues ...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, keysAndValues ...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, keysAndValues ...any)
- func (l *Logger) Warnz(msg string, fields ...zap.Field)
- func (l *Logger) With(fields ...string) types.Logger
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 ¶
NewGin returns a *Logger instance that contains *zap.Logger. The difference between NewGin and New is disable fields "caller", "level" and "msg".
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 ¶
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()`
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 ¶
New returns *Logger instance that contains *zap.Logger and *zap.SugaredLogger and implements types.Logger.
func (*Logger) With ¶
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), )