From c25a229e5faaaa080cefdf83d42d06f7633d8c68 Mon Sep 17 00:00:00 2001 From: Dan Markhasin Date: Wed, 18 Dec 2024 09:45:36 +0200 Subject: [PATCH] Don't discard klog logs at the highest log levels (debug and trace) --- main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index dced351fdb..12e1f8263e 100644 --- a/main.go +++ b/main.go @@ -100,10 +100,12 @@ func main() { } log.SetLevel(ll) - // Klog V2 is used by k8s.io/apimachinery/pkg/labels and can throw (a lot) of irrelevant logs - // See https://github.com/kubernetes-sigs/external-dns/issues/2348 - defer klog.ClearLogger() - klog.SetLogger(logr.Discard()) + if ll >= log.DebugLevel { + // Klog V2 is used by k8s.io/apimachinery/pkg/labels and can throw (a lot) of irrelevant logs + // See https://github.com/kubernetes-sigs/external-dns/issues/2348 + defer klog.ClearLogger() + klog.SetLogger(logr.Discard()) + } ctx, cancel := context.WithCancel(context.Background())