chore: fix noisy info logs (#1808)

* refine logging

* keep progress message at level 0
This commit is contained in:
Diamon Wiggins
2025-07-09 20:58:47 -04:00
committed by GitHub
parent 38d8a45171
commit 7a6bffeff5
8 changed files with 20 additions and 11 deletions

View File

@@ -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
}

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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
}

View File

@@ -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.

View File

@@ -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

View File

@@ -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")