Skip to content

Commit

Permalink
ref: add caller tag to logger result
Browse files Browse the repository at this point in the history
  • Loading branch information
kenriortega committed Nov 11, 2021
1 parent f449cf4 commit 1779b2a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,28 @@ import (
var log *zap.Logger

func init() {

config := zap.NewProductionConfig()
encoderConfig := zap.NewProductionEncoderConfig()
encoderConfig.TimeKey = "timestamp"
encoderConfig.CallerKey = "caller"
encoderConfig.StacktraceKey = ""
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
encoderConfig.EncodeCaller = zapcore.ShortCallerEncoder
config.EncoderConfig = encoderConfig

w := zapcore.AddSync(&lumberjack.Logger{
Filename: "./ngonx-log/ngonx.log",
MaxSize: 500, // megabytes
MaxBackups: 3,
MaxAge: 28, // days
})

core := zapcore.NewCore(
zapcore.NewConsoleEncoder(encoderConfig),
zapcore.NewConsoleEncoder(config.EncoderConfig),
w,
zap.InfoLevel,
)
log = zap.New(core)

log = zap.New(core, zap.AddCaller(), zap.AddCallerSkip(1))
}

// LogInfo wrap for log.info
Expand Down

0 comments on commit 1779b2a

Please sign in to comment.