From 2d2f85f261de692f8f95c9f76a7399bf3f920fe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20B=C3=BCringer?= <4662360+sbueringer@users.noreply.github.com> Date: Fri, 27 Aug 2021 18:06:04 +0200 Subject: [PATCH] Manager should use the global logger, reduce log names verbosity (#1648) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently a controller using the default logger has very verbose names such as "controller-runtime/manager/controller/", this changeset reduces the verbosity of each log line to mostly have controller/. Signed-off-by: Stefan Büringer buringerst@vmware.com --- pkg/log/deleg.go | 2 +- pkg/manager/manager.go | 4 ++-- pkg/manager/manager_test.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/log/deleg.go b/pkg/log/deleg.go index bbd9c9c756..9d73947dac 100644 --- a/pkg/log/deleg.go +++ b/pkg/log/deleg.go @@ -76,7 +76,7 @@ func (p *loggerPromise) V(l *DelegatingLogger, level int) *loggerPromise { // Fulfill instantiates the Logger with the provided logger. func (p *loggerPromise) Fulfill(parentLogger logr.Logger) { - var logger = parentLogger + logger := logr.WithCallDepth(parentLogger, 1) if p.name != nil { logger = logger.WithName(*p.name) } diff --git a/pkg/manager/manager.go b/pkg/manager/manager.go index 903e3e47f9..2d2733f0a6 100644 --- a/pkg/manager/manager.go +++ b/pkg/manager/manager.go @@ -37,9 +37,9 @@ import ( "sigs.k8s.io/controller-runtime/pkg/config" "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" "sigs.k8s.io/controller-runtime/pkg/healthz" - logf "sigs.k8s.io/controller-runtime/pkg/internal/log" intrec "sigs.k8s.io/controller-runtime/pkg/internal/recorder" "sigs.k8s.io/controller-runtime/pkg/leaderelection" + "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/metrics" "sigs.k8s.io/controller-runtime/pkg/recorder" "sigs.k8s.io/controller-runtime/pkg/runtime/inject" @@ -572,7 +572,7 @@ func setOptionsDefaults(options Options) Options { } if options.Logger == nil { - options.Logger = logf.RuntimeLog.WithName("manager") + options.Logger = log.Log } return options diff --git a/pkg/manager/manager_test.go b/pkg/manager/manager_test.go index 2c785ad9f3..b697751799 100644 --- a/pkg/manager/manager_test.go +++ b/pkg/manager/manager_test.go @@ -45,10 +45,10 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/cluster" "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1" - logf "sigs.k8s.io/controller-runtime/pkg/internal/log" intrec "sigs.k8s.io/controller-runtime/pkg/internal/recorder" "sigs.k8s.io/controller-runtime/pkg/leaderelection" fakeleaderelection "sigs.k8s.io/controller-runtime/pkg/leaderelection/fake" + "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/metrics" "sigs.k8s.io/controller-runtime/pkg/reconcile" "sigs.k8s.io/controller-runtime/pkg/recorder" @@ -1444,7 +1444,7 @@ var _ = Describe("manger.Manager", func() { }, log: func(logger logr.Logger) error { defer GinkgoRecover() - Expect(logger).To(Equal(logf.RuntimeLog.WithName("manager"))) + Expect(logger).To(Equal(log.Log)) return nil }, })