silence the 'log.SetLogger(...) was never called; logs will not be displayed' error

Signed-off-by: zhzhuang-zju <m17799853869@163.com>
This commit is contained in:
zhzhuang-zju 2024-04-29 20:12:24 +08:00
parent 0e3c382bd0
commit 3989c4a82a
4 changed files with 28 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import (
"k8s.io/component-base/cli"
_ "k8s.io/component-base/logs/json/register" // for JSON log format registration
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
_ "sigs.k8s.io/controller-runtime/pkg/metrics"
@ -29,6 +30,12 @@ import (
func main() {
ctx := controllerruntime.SetupSignalHandler()
// Starting from version 0.15.0, controller-runtime expects its consumers to set a logger through log.SetLogger.
// If SetLogger is not called within the first 30 seconds of a binaries lifetime, it will get
// set to a NullLogSink and report an error. Here's to silence the "log.SetLogger(...) was never called; logs will not be displayed" error
// by setting a logger through log.SetLogger.
// More info refer to: https://github.com/karmada-io/karmada/pull/4885.
controllerruntime.SetLogger(klog.Background())
cmd := app.NewControllerManagerCommand(ctx)
code := cli.Run(cmd)
os.Exit(code)

View File

@ -21,6 +21,7 @@ import (
"k8s.io/component-base/cli"
_ "k8s.io/component-base/logs/json/register" // for JSON log format registration
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
"github.com/karmada-io/karmada/cmd/metrics-adapter/app"
@ -28,6 +29,12 @@ import (
func main() {
ctx := controllerruntime.SetupSignalHandler()
// Starting from version 0.15.0, controller-runtime expects its consumers to set a logger through log.SetLogger.
// If SetLogger is not called within the first 30 seconds of a binaries lifetime, it will get
// set to a NullLogSink and report an error. Here's to silence the "log.SetLogger(...) was never called; logs will not be displayed" error
// by setting a logger through log.SetLogger.
// More info refer to: https://github.com/karmada-io/karmada/pull/4885.
controllerruntime.SetLogger(klog.Background())
cmd := app.NewMetricsAdapterCommand(ctx)
code := cli.Run(cmd)
os.Exit(code)

View File

@ -21,6 +21,7 @@ import (
"k8s.io/component-base/cli"
_ "k8s.io/component-base/logs/json/register" // for JSON log format registration
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
"github.com/karmada-io/karmada/cmd/webhook/app"
@ -28,6 +29,12 @@ import (
func main() {
ctx := controllerruntime.SetupSignalHandler()
// Starting from version 0.15.0, controller-runtime expects its consumers to set a logger through log.SetLogger.
// If SetLogger is not called within the first 30 seconds of a binaries lifetime, it will get
// set to a NullLogSink and report an error. Here's to silence the "log.SetLogger(...) was never called; logs will not be displayed" error
// by setting a logger through log.SetLogger.
// More info refer to: https://github.com/karmada-io/karmada/pull/4885.
controllerruntime.SetLogger(klog.Background())
cmd := app.NewWebhookCommand(ctx)
code := cli.Run(cmd)
os.Exit(code)

View File

@ -21,6 +21,7 @@ import (
"k8s.io/component-base/cli"
_ "k8s.io/component-base/logs/json/register" // for JSON log format registration
"k8s.io/klog/v2"
controllerruntime "sigs.k8s.io/controller-runtime"
"github.com/karmada-io/karmada/examples/customresourceinterpreter/webhook/app"
@ -28,6 +29,12 @@ import (
func main() {
ctx := controllerruntime.SetupSignalHandler()
// Starting from version 0.15.0, controller-runtime expects its consumers to set a logger through log.SetLogger.
// If SetLogger is not called within the first 30 seconds of a binaries lifetime, it will get
// set to a NullLogSink and report an error. Here's to silence the "log.SetLogger(...) was never called; logs will not be displayed" error
// by setting a logger through log.SetLogger.
// More info refer to: https://github.com/karmada-io/karmada/pull/4885.
controllerruntime.SetLogger(klog.Background())
cmd := app.NewWebhookCommand(ctx)
code := cli.Run(cmd)
os.Exit(code)