From 7a6bffeff52cbea7a2e3b9c3c13dec985e3e62a4 Mon Sep 17 00:00:00 2001 From: Diamon Wiggins <38189728+diamonwiggins@users.noreply.github.com> Date: Wed, 9 Jul 2025 20:58:47 -0400 Subject: [PATCH] chore: fix noisy info logs (#1808) * refine logging * keep progress message at level 0 --- pkg/analyze/analyzer.go | 6 +++--- pkg/collect/ceph.go | 2 +- pkg/collect/etcd.go | 2 +- pkg/collect/http.go | 2 +- pkg/collect/registry.go | 2 +- pkg/logger/logger.go | 13 +++++++++++-- pkg/preflight/collect.go | 2 +- pkg/supportbundle/load.go | 2 +- 8 files changed, 20 insertions(+), 11 deletions(-) diff --git a/pkg/analyze/analyzer.go b/pkg/analyze/analyzer.go index 948b0f73..fdcec024 100644 --- a/pkg/analyze/analyzer.go +++ b/pkg/analyze/analyzer.go @@ -80,7 +80,7 @@ func HostAnalyze( isExcluded, _ := analyzer.IsExcluded() if isExcluded { - klog.Infof("excluding %q analyzer", analyzer.Title()) + klog.V(1).Infof("excluding %q analyzer", analyzer.Title()) span.SetAttributes(attribute.Bool(constants.EXCLUDED, true)) return nil } @@ -124,7 +124,7 @@ func Analyze( analyzerInst := GetAnalyzer(analyzer) if analyzerInst == nil { - klog.Info("Non-existent analyzer found in the spec. Please double-check the spelling and indentation of the analyzers in the spec.") + klog.V(1).Info("Non-existent analyzer found in the spec. Please double-check the spelling and indentation of the analyzers in the spec.") return nil, nil } @@ -138,7 +138,7 @@ func Analyze( return nil, err } if isExcluded { - klog.Infof("excluding %q analyzer", analyzerInst.Title()) + klog.V(1).Infof("excluding %q analyzer", analyzerInst.Title()) span.SetAttributes(attribute.Bool(constants.EXCLUDED, true)) return nil, nil } diff --git a/pkg/collect/ceph.go b/pkg/collect/ceph.go index 734353a2..5c4a7805 100644 --- a/pkg/collect/ceph.go +++ b/pkg/collect/ceph.go @@ -246,7 +246,7 @@ func findRookCephToolsPod(ctx context.Context, c *CollectCeph, namespace string) return &pods[0], nil } - klog.Info("rook ceph tools pod not found") + klog.V(1).Info("rook ceph tools pod not found") return nil, nil } diff --git a/pkg/collect/etcd.go b/pkg/collect/etcd.go index 5a5f0bf2..d73f15de 100644 --- a/pkg/collect/etcd.go +++ b/pkg/collect/etcd.go @@ -105,7 +105,7 @@ func (c *CollectEtcd) Collect(progressChan chan<- interface{}) (CollectorResult, fileName := generateFilenameFromCommand(command) stdout, stderr, err := debugInstance.executeCommand(command) if err != nil { - klog.Infof("failed to exec command %s: %v", command, err) + klog.V(2).Infof("failed to exec command %s: %v", command, err) continue } if len(stdout) > 0 { diff --git a/pkg/collect/http.go b/pkg/collect/http.go index 05fcd93a..db21f08a 100644 --- a/pkg/collect/http.go +++ b/pkg/collect/http.go @@ -213,7 +213,7 @@ func responseToOutput(response *http.Response, err error) ([]byte, error) { var rawJSON json.RawMessage if len(body) > 0 { if err := json.Unmarshal(body, &rawJSON); err != nil { - klog.Infof("failed to unmarshal response body as JSON: %+v", err) + klog.V(2).Infof("failed to unmarshal response body as JSON: %+v", err) rawJSON = json.RawMessage{} } } else { diff --git a/pkg/collect/registry.go b/pkg/collect/registry.go index c343ab0e..7527dc91 100644 --- a/pkg/collect/registry.go +++ b/pkg/collect/registry.go @@ -117,7 +117,7 @@ func imageExists(namespace string, clientConfig *rest.Config, registryCollector remoteImage, err := imageRef.NewImage(context.Background(), &sysCtx) if err == nil { - klog.Infof("image %s exists", image) + klog.V(2).Infof("image %s exists", image) remoteImage.Close() return true, nil } diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index 67a43203..bdcb371d 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -67,8 +67,17 @@ func InitKlog(verbosity int) { // SetupLogger sets up klog logger based on viper configuration. func SetupLogger(v *viper.Viper) { - quiet := v.GetBool("debug") || v.IsSet("v") - SetQuiet(!quiet) + shouldShowLogs := v.GetBool("debug") || v.IsSet("v") + SetQuiet(!shouldShowLogs) + + // If verbosity is set, configure klog verbosity level + if v.IsSet("v") { + verbosity := v.GetInt("v") + if verbosity > 0 { + // Use the existing InitKlog function to set verbosity + InitKlog(verbosity) + } + } } // SetQuiet enables or disables klog logger. diff --git a/pkg/preflight/collect.go b/pkg/preflight/collect.go index d6ffeefc..4e3d9fac 100644 --- a/pkg/preflight/collect.go +++ b/pkg/preflight/collect.go @@ -243,7 +243,7 @@ func CollectWithContext(ctx context.Context, opts CollectOpts, p *troubleshootv1 isExcluded, _ := collector.IsExcluded() if isExcluded { - klog.Infof("excluding %q collector", collector.Title()) + klog.V(1).Infof("excluding %q collector", collector.Title()) span.SetAttributes(attribute.Bool(constants.EXCLUDED, true)) span.End() continue diff --git a/pkg/supportbundle/load.go b/pkg/supportbundle/load.go index 7dd60cd7..c3b85d10 100644 --- a/pkg/supportbundle/load.go +++ b/pkg/supportbundle/load.go @@ -80,7 +80,7 @@ func ParseSupportBundle(doc []byte, followURI bool) (*troubleshootv1beta2.Suppor // use the upstream spec, otherwise fall back to // what's defined in the current spec if supportBundle.Spec.Uri != "" && followURI { - klog.Infof("using upstream reference: %+v\n", supportBundle.Spec.Uri) + klog.V(1).Infof("using upstream reference: %+v\n", supportBundle.Spec.Uri) upstreamSupportBundleContent, err := LoadSupportBundleSpec(supportBundle.Spec.Uri) if err != nil { klog.Errorf("failed to load upstream supportbundle, falling back")