u
This commit is contained in:
1 parent
be8eaae7c5
commit
d6dd5b032d
11 files changed
+202
-112
No files matched your search
@@ -180,6 +180,14 @@ func newConsoleEncoder(enableColor bool) zapcore.Encoder {
|
||||
pid := os.Getpid()
|
||||
enc.AppendString(fmt.Sprintf("[%d] [%d] %s", pid, routinex.CurGID(), caller.TrimmedPath()))
|
||||
},
|
||||
EncodeDuration: func(d time.Duration, enc zapcore.PrimitiveArrayEncoder) {
|
||||
ms := d.Milliseconds()
|
||||
if ms < 1000 {
|
||||
enc.AppendString(fmt.Sprintf("%dms", ms))
|
||||
} else {
|
||||
enc.AppendString(fmt.Sprintf("%.2fs", d.Seconds()))
|
||||
}
|
||||
},
|
||||
}
|
||||
return zapcore.NewConsoleEncoder(cfg)
|
||||
}
|
||||
@@ -192,6 +200,17 @@ func newJSONEncoder() zapcore.Encoder {
|
||||
}
|
||||
cfg.EncodeLevel = zapcore.CapitalLevelEncoder
|
||||
cfg.EncodeCaller = zapcore.ShortCallerEncoder
|
||||
|
||||
// 智能 duration 输出
|
||||
cfg.EncodeDuration = func(d time.Duration, enc zapcore.PrimitiveArrayEncoder) {
|
||||
ms := d.Milliseconds()
|
||||
if ms < 1000 {
|
||||
enc.AppendString(fmt.Sprintf("%dms", ms))
|
||||
} else {
|
||||
enc.AppendString(fmt.Sprintf("%.2fs", d.Seconds()))
|
||||
}
|
||||
}
|
||||
|
||||
return zapcore.NewJSONEncoder(cfg)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user