Skip to content

Commit 7a6bffe

Browse files
chore: fix noisy info logs (#1808)
* refine logging * keep progress message at level 0
1 parent 38d8a45 commit 7a6bffe

File tree

8 files changed

+20
-11
lines changed

8 files changed

+20
-11
lines changed

pkg/analyze/analyzer.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func HostAnalyze(
8080

8181
isExcluded, _ := analyzer.IsExcluded()
8282
if isExcluded {
83-
klog.Infof("excluding %q analyzer", analyzer.Title())
83+
klog.V(1).Infof("excluding %q analyzer", analyzer.Title())
8484
span.SetAttributes(attribute.Bool(constants.EXCLUDED, true))
8585
return nil
8686
}
@@ -124,7 +124,7 @@ func Analyze(
124124

125125
analyzerInst := GetAnalyzer(analyzer)
126126
if analyzerInst == nil {
127-
klog.Info("Non-existent analyzer found in the spec. Please double-check the spelling and indentation of the analyzers in the spec.")
127+
klog.V(1).Info("Non-existent analyzer found in the spec. Please double-check the spelling and indentation of the analyzers in the spec.")
128128
return nil, nil
129129
}
130130

@@ -138,7 +138,7 @@ func Analyze(
138138
return nil, err
139139
}
140140
if isExcluded {
141-
klog.Infof("excluding %q analyzer", analyzerInst.Title())
141+
klog.V(1).Infof("excluding %q analyzer", analyzerInst.Title())
142142
span.SetAttributes(attribute.Bool(constants.EXCLUDED, true))
143143
return nil, nil
144144
}

pkg/collect/ceph.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func findRookCephToolsPod(ctx context.Context, c *CollectCeph, namespace string)
246246
return &pods[0], nil
247247
}
248248

249-
klog.Info("rook ceph tools pod not found")
249+
klog.V(1).Info("rook ceph tools pod not found")
250250

251251
return nil, nil
252252
}

pkg/collect/etcd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (c *CollectEtcd) Collect(progressChan chan<- interface{}) (CollectorResult,
105105
fileName := generateFilenameFromCommand(command)
106106
stdout, stderr, err := debugInstance.executeCommand(command)
107107
if err != nil {
108-
klog.Infof("failed to exec command %s: %v", command, err)
108+
klog.V(2).Infof("failed to exec command %s: %v", command, err)
109109
continue
110110
}
111111
if len(stdout) > 0 {

pkg/collect/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func responseToOutput(response *http.Response, err error) ([]byte, error) {
213213
var rawJSON json.RawMessage
214214
if len(body) > 0 {
215215
if err := json.Unmarshal(body, &rawJSON); err != nil {
216-
klog.Infof("failed to unmarshal response body as JSON: %+v", err)
216+
klog.V(2).Infof("failed to unmarshal response body as JSON: %+v", err)
217217
rawJSON = json.RawMessage{}
218218
}
219219
} else {

pkg/collect/registry.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func imageExists(namespace string, clientConfig *rest.Config, registryCollector
117117

118118
remoteImage, err := imageRef.NewImage(context.Background(), &sysCtx)
119119
if err == nil {
120-
klog.Infof("image %s exists", image)
120+
klog.V(2).Infof("image %s exists", image)
121121
remoteImage.Close()
122122
return true, nil
123123
}

pkg/logger/logger.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,17 @@ func InitKlog(verbosity int) {
6767

6868
// SetupLogger sets up klog logger based on viper configuration.
6969
func SetupLogger(v *viper.Viper) {
70-
quiet := v.GetBool("debug") || v.IsSet("v")
71-
SetQuiet(!quiet)
70+
shouldShowLogs := v.GetBool("debug") || v.IsSet("v")
71+
SetQuiet(!shouldShowLogs)
72+
73+
// If verbosity is set, configure klog verbosity level
74+
if v.IsSet("v") {
75+
verbosity := v.GetInt("v")
76+
if verbosity > 0 {
77+
// Use the existing InitKlog function to set verbosity
78+
InitKlog(verbosity)
79+
}
80+
}
7281
}
7382

7483
// SetQuiet enables or disables klog logger.

pkg/preflight/collect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func CollectWithContext(ctx context.Context, opts CollectOpts, p *troubleshootv1
243243

244244
isExcluded, _ := collector.IsExcluded()
245245
if isExcluded {
246-
klog.Infof("excluding %q collector", collector.Title())
246+
klog.V(1).Infof("excluding %q collector", collector.Title())
247247
span.SetAttributes(attribute.Bool(constants.EXCLUDED, true))
248248
span.End()
249249
continue

pkg/supportbundle/load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func ParseSupportBundle(doc []byte, followURI bool) (*troubleshootv1beta2.Suppor
8080
// use the upstream spec, otherwise fall back to
8181
// what's defined in the current spec
8282
if supportBundle.Spec.Uri != "" && followURI {
83-
klog.Infof("using upstream reference: %+v\n", supportBundle.Spec.Uri)
83+
klog.V(1).Infof("using upstream reference: %+v\n", supportBundle.Spec.Uri)
8484
upstreamSupportBundleContent, err := LoadSupportBundleSpec(supportBundle.Spec.Uri)
8585
if err != nil {
8686
klog.Errorf("failed to load upstream supportbundle, falling back")

0 commit comments

Comments
 (0)