升级wrapper的日志

This commit is contained in:
白茶清欢 2021-03-05 00:46:41 +08:00
parent d539f84737
commit 38a2e3b582
3 changed files with 7 additions and 3 deletions

View File

@ -68,7 +68,11 @@ func NewLogger(loggerLevel zapcore.Level, splitConfig *RotateLogConfig, optionFu
core := zapcore.NewTee(fileHandlerList...) core := zapcore.NewTee(fileHandlerList...)
// 需要传入 zap.AddCaller() 才会显示打日志点的文件名和行数, 跳过一行可以直接显示业务代码行号,否则显示日志包行号 // 需要传入 zap.AddCaller() 才会显示打日志点的文件名和行数, 跳过一行可以直接显示业务代码行号,否则显示日志包行号
log := zap.New(core, zap.AddCaller(), zap.AddCallerSkip(3)) logConfList := []zap.Option{}
if o.WithCaller {
logConfList = append(logConfList, zap.AddCaller(), zap.AddCallerSkip(o.WithCallerSkip))
}
log := zap.New(core, logConfList...)
return log, nil return log, nil
} }

View File

@ -28,7 +28,7 @@ import (
// //
// Date : 9:56 下午 2021/3/1 // Date : 9:56 下午 2021/3/1
func NewGormV2(loggerLevel zapcore.Level, consoleOutput bool, encoder zapcore.Encoder, splitConfig *logger2.RotateLogConfig, traceIDField string) (logger.Interface, error) { func NewGormV2(loggerLevel zapcore.Level, consoleOutput bool, encoder zapcore.Encoder, splitConfig *logger2.RotateLogConfig, traceIDField string) (logger.Interface, error) {
logConfList := []logger2.SetLoggerOptionFunc{logger2.WithEncoder(encoder)} logConfList := []logger2.SetLoggerOptionFunc{logger2.WithEncoder(encoder), logger2.WithCallerSkip(3), logger2.WithCaller()}
if consoleOutput { if consoleOutput {
logConfList = append(logConfList, logger2.WithConsoleOutput()) logConfList = append(logConfList, logger2.WithConsoleOutput())
} }

View File

@ -27,7 +27,7 @@ func NewGinLogger(loggerLevel zapcore.Level, consoleOutput bool, encoder zapcore
err error err error
l *zap.Logger l *zap.Logger
) )
logConfList := []logger2.SetLoggerOptionFunc{logger2.WithEncoder(encoder)} logConfList := []logger2.SetLoggerOptionFunc{logger2.WithEncoder(encoder), logger2.WithCaller(), logger2.WithCallerSkip(1)}
if consoleOutput { if consoleOutput {
logConfList = append(logConfList, logger2.WithConsoleOutput()) logConfList = append(logConfList, logger2.WithConsoleOutput())
} }