From 9904718d0874b8c248065d6d205defdd450cf4cf Mon Sep 17 00:00:00 2001 From: Vishal Choudhary Date: Wed, 10 Jul 2024 18:01:19 +0530 Subject: [PATCH] fix: rename level 1 logs to INFO from DEBUG (#10617) Signed-off-by: Vishal Choudhary Co-authored-by: shuting --- pkg/logging/log.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/logging/log.go b/pkg/logging/log.go index f79f491f13..9a7c18fe56 100644 --- a/pkg/logging/log.go +++ b/pkg/logging/log.go @@ -59,8 +59,10 @@ func Setup(logFormat string, loggingTimestampFormat string, level int) error { switch logFormat { case TextFormat: zc = zap.NewDevelopmentConfig() + zc.EncoderConfig.EncodeLevel = zapLevelEncoderText case JSONFormat: zc = zap.NewProductionConfig() + zc.EncoderConfig.EncodeLevel = zapLevelEncoderJson default: return errors.New("log format not recognized, pass `text` for text mode or `json` to enable JSON logging") } @@ -186,3 +188,21 @@ func (a *writerAdapter) Write(p []byte) (int, error) { func StdLogger(logger logr.Logger, prefix string) *stdlog.Logger { return stdlog.New(&writerAdapter{logger: logger}, prefix, stdlog.LstdFlags) } + +func zapLevelEncoderText(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) { + enc.AppendString(zapLevelToString(l)) +} + +func zapLevelEncoderJson(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder) { + enc.AppendString(strings.ToLower(zapLevelToString(l))) +} + +func zapLevelToString(zapLevel zapcore.Level) string { + if zapLevel <= 0 && zapLevel >= -2 { + return "INFO" + } else if zapLevel <= -3 { + return "DEBUG" + } else { + return zapLevel.CapitalString() + } +}