Skip to content

Commit bb46051

Browse files
fix: honor klog -stderrthreshold when -logtostderr is enabled
klog v2 defaults -logtostderr to true. When this flag is active, the -stderrthreshold flag is silently ignored — all log messages are unconditionally written to stderr regardless of severity. Opt into the fixed behavior introduced in klog v2.140.0 by setting legacy_stderr_threshold_behavior=false. The default stderrthreshold remains INFO so the observable behavior is unchanged — users who want filtering can now pass -stderrthreshold=WARNING and it will take effect. Ref: kubernetes/klog#212, kubernetes/klog#432 Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
1 parent 0713a5b commit bb46051

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

cmd/root.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ func init() {
117117
rootCmd.AddCommand(detectCmd)
118118

119119
klog.InitFlags(nil)
120+
// Opt into the new klog behavior so that -stderrthreshold is honored even
121+
// when -logtostderr=true (the default).
122+
// Ref: kubernetes/klog#212, kubernetes/klog#432
123+
_ = flag.Set("legacy_stderr_threshold_behavior", "false") //nolint:errcheck
124+
_ = flag.Set("stderrthreshold", "INFO") //nolint:errcheck
120125
pflag.CommandLine.AddGoFlag(flag.CommandLine.Lookup("v"))
121126
}
122127

0 commit comments

Comments
 (0)