From be92e2c705dfbb4022a3c343c4c54e92fa1fc4de Mon Sep 17 00:00:00 2001 From: Bazaah Date: Sat, 10 Dec 2022 19:39:57 +0000 Subject: [PATCH] config: pad log level longest that can be created is DPANIC, or 6 wide. Upstream-Ref: https://github.com/uber-go/zap/blob/v1.24.0/zapcore/level.go#L135 --- config/context.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/context.go b/config/context.go index d7e94c4..80da232 100644 --- a/config/context.go +++ b/config/context.go @@ -8,6 +8,7 @@ package config import ( "context" + "fmt" "strings" "time" @@ -36,7 +37,9 @@ func initLogger(ll string) *zap.Logger { base.EncoderConfig.EncodeTime = func(t time.Time, enc zapcore.PrimitiveArrayEncoder) { enc.AppendInt64(t.Unix()) } - base.EncoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder + base.EncoderConfig.EncodeLevel = func(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) { + enc.AppendString(fmt.Sprintf("%-6s", l.CapitalString())) + } base.EncoderConfig.ConsoleSeparator = " " base.DisableCaller = true return zap.Must(base.Build())