diff --git a/bootstrap/kubeadm/main.go b/bootstrap/kubeadm/main.go index f0715ca99a82..115aec01272a 100644 --- a/bootstrap/kubeadm/main.go +++ b/bootstrap/kubeadm/main.go @@ -36,7 +36,6 @@ import ( "k8s.io/component-base/logs" _ "k8s.io/component-base/logs/json/register" "k8s.io/klog/v2" - "k8s.io/klog/v2/klogr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -150,11 +149,8 @@ func main() { os.Exit(1) } - // 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))) + // klog.Background will automatically use the right logger. + ctrl.SetLogger(klog.Background()) if profilerAddress != "" { klog.Infof("Profiler listening for requests at %s", profilerAddress) diff --git a/controlplane/kubeadm/main.go b/controlplane/kubeadm/main.go index 8cd4dca2d55d..4677c4ab2b7a 100644 --- a/controlplane/kubeadm/main.go +++ b/controlplane/kubeadm/main.go @@ -38,7 +38,6 @@ import ( "k8s.io/component-base/logs" _ "k8s.io/component-base/logs/json/register" "k8s.io/klog/v2" - "k8s.io/klog/v2/klogr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -153,11 +152,8 @@ func main() { os.Exit(1) } - // 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))) + // klog.Background will automatically use the right logger. + ctrl.SetLogger(klog.Background()) if profilerAddress != "" { klog.Infof("Profiler listening for requests at %s", profilerAddress) diff --git a/docs/book/src/developer/providers/v1.1-to-v1.2.md b/docs/book/src/developer/providers/v1.1-to-v1.2.md index bd715c267dbf..35c5bad08cd4 100644 --- a/docs/book/src/developer/providers/v1.1-to-v1.2.md +++ b/docs/book/src/developer/providers/v1.1-to-v1.2.md @@ -70,11 +70,8 @@ in ClusterAPI are kept in sync with the versions used by `sigs.k8s.io/controller + os.Exit(1) + } + - + // 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))) + + // klog.Background will automatically use the right logger. + + ctrl.SetLogger(klog.Background()) - ctrl.SetLogger(klogr.New()) ``` diff --git a/main.go b/main.go index eb0aa64251c4..25443153b4af 100644 --- a/main.go +++ b/main.go @@ -36,7 +36,6 @@ import ( "k8s.io/component-base/logs" _ "k8s.io/component-base/logs/json/register" "k8s.io/klog/v2" - "k8s.io/klog/v2/klogr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -208,11 +207,8 @@ func main() { os.Exit(1) } - // 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))) + // klog.Background will automatically use the right logger. + ctrl.SetLogger(klog.Background()) 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 9a1f0091269d..aaf7397438c3 100644 --- a/test/infrastructure/docker/main.go +++ b/test/infrastructure/docker/main.go @@ -34,7 +34,6 @@ import ( "k8s.io/component-base/logs" _ "k8s.io/component-base/logs/json/register" "k8s.io/klog/v2" - "k8s.io/klog/v2/klogr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/controller" @@ -123,11 +122,8 @@ func main() { os.Exit(1) } - // 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))) + // klog.Background will automatically use the right logger. + ctrl.SetLogger(klog.Background()) if profilerAddress != "" { klog.Infof("Profiler listening for requests at %s", profilerAddress)