From 3d920cb377049c0aac71b350c9e43764bd7ef36c Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Wed, 23 Feb 2022 08:44:02 +0100 Subject: [PATCH] logging: set correct klog format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Büringer buringerst@vmware.com --- bootstrap/kubeadm/main.go | 13 +++++-------- controlplane/kubeadm/main.go | 13 +++++-------- main.go | 13 +++++-------- test/infrastructure/docker/main.go | 13 +++++-------- 4 files changed, 20 insertions(+), 32 deletions(-) diff --git a/bootstrap/kubeadm/main.go b/bootstrap/kubeadm/main.go index 46320bfacb18..49349b37a101 100644 --- a/bootstrap/kubeadm/main.go +++ b/bootstrap/kubeadm/main.go @@ -150,14 +150,11 @@ func main() { os.Exit(1) } - // The JSON log format requires the Klog format in klog, otherwise log lines - // are serialized twice, e.g.: - // { ... "msg":"controller/cluster \"msg\"=\"Starting workers\"\n"} - if logOptions.Config.Format == logs.JSONLogFormat { - ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog))) - } else { - ctrl.SetLogger(klogr.New()) - } + // Set the Klog format, as the Serialize format shouldn't be used anymore. + // This makes sure that the logs are formatted correctly, i.e.: + // * JSON logging format: msg isn't serialized twice + // * text logging format: values are formatted with their .String() func. + ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog))) if profilerAddress != "" { klog.Infof("Profiler listening for requests at %s", profilerAddress) diff --git a/controlplane/kubeadm/main.go b/controlplane/kubeadm/main.go index 696f0a5c0866..15c6b403cfb5 100644 --- a/controlplane/kubeadm/main.go +++ b/controlplane/kubeadm/main.go @@ -153,14 +153,11 @@ func main() { os.Exit(1) } - // The JSON log format requires the Klog format in klog, otherwise log lines - // are serialized twice, e.g.: - // { ... "msg":"controller/cluster \"msg\"=\"Starting workers\"\n"} - if logOptions.Config.Format == logs.JSONLogFormat { - ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog))) - } else { - ctrl.SetLogger(klogr.New()) - } + // Set the Klog format, as the Serialize format shouldn't be used anymore. + // This makes sure that the logs are formatted correctly, i.e.: + // * JSON logging format: msg isn't serialized twice + // * text logging format: values are formatted with their .String() func. + ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog))) if profilerAddress != "" { klog.Infof("Profiler listening for requests at %s", profilerAddress) diff --git a/main.go b/main.go index 3f2ed449d641..762341fe89f1 100644 --- a/main.go +++ b/main.go @@ -192,14 +192,11 @@ func main() { os.Exit(1) } - // The JSON log format requires the Klog format in klog, otherwise log lines - // are serialized twice, e.g.: - // { ... "msg":"controller/cluster \"msg\"=\"Starting workers\"\n"} - if logOptions.Config.Format == logs.JSONLogFormat { - ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog))) - } else { - ctrl.SetLogger(klogr.New()) - } + // Set the Klog format, as the Serialize format shouldn't be used anymore. + // This makes sure that the logs are formatted correctly, i.e.: + // * JSON logging format: msg isn't serialized twice + // * text logging format: values are formatted with their .String() func. + ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog))) if profilerAddress != "" { klog.Infof("Profiler listening for requests at %s", profilerAddress) diff --git a/test/infrastructure/docker/main.go b/test/infrastructure/docker/main.go index 16d970623f5d..7b539a5d185f 100644 --- a/test/infrastructure/docker/main.go +++ b/test/infrastructure/docker/main.go @@ -123,14 +123,11 @@ func main() { os.Exit(1) } - // The JSON log format requires the Klog format in klog, otherwise log lines - // are serialized twice, e.g.: - // { ... "msg":"controller/cluster \"msg\"=\"Starting workers\"\n"} - if logOptions.Config.Format == logs.JSONLogFormat { - ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog))) - } else { - ctrl.SetLogger(klogr.New()) - } + // Set the Klog format, as the Serialize format shouldn't be used anymore. + // This makes sure that the logs are formatted correctly, i.e.: + // * JSON logging format: msg isn't serialized twice + // * text logging format: values are formatted with their .String() func. + ctrl.SetLogger(klogr.NewWithOptions(klogr.WithFormat(klogr.FormatKlog))) if profilerAddress != "" { klog.Infof("Profiler listening for requests at %s", profilerAddress)