From 8a59e240c6b4553cd0c86264ec883bd05042ba9a Mon Sep 17 00:00:00 2001 From: yinka Date: Fri, 28 Oct 2022 21:52:58 +0100 Subject: [PATCH] fix: configure klog and global logger to use zapr in json mode (#5144) * configure klog and global logger to use zapr in json mode Signed-off-by: damilola olayinka * changes Signed-off-by: damilola olayinka * make zapr compatible with klog's -v argument Signed-off-by: damilola olayinka * remove changes Signed-off-by: damilola olayinka * remove logLevel flag Signed-off-by: damilola olayinka Signed-off-by: damilola olayinka Co-authored-by: shuting --- pkg/logging/log.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/logging/log.go b/pkg/logging/log.go index 3c00f8003a85..a501fda99b0f 100644 --- a/pkg/logging/log.go +++ b/pkg/logging/log.go @@ -43,6 +43,7 @@ func Init(flags *flag.FlagSet) { // Setup configures the logger with the supplied log format. // It returns an error if the JSON logger could not be initialized or passed logFormat is not recognized. +// LogLevel parameter is used to configure zap. func Setup(logFormat string) error { switch logFormat { case TextFormat: @@ -53,9 +54,9 @@ func Setup(logFormat string) error { if err != nil { return err } - klog.SetLogger(zapr.NewLogger(zapLog)) - // in json mode we use FormatKlog format - globalLog = klog.NewKlogr() + globalLog = zapr.NewLogger(zapLog) + // in json mode we configure klog and global logger to use zapr + klog.SetLogger(globalLog.WithName("klog")) default: return errors.New("log format not recognized, pass `text` for text mode or `json` to enable JSON logging") }