fix: honor -stderrthreshold when -logtostderr is set#850
Merged
sudermanjr merged 2 commits intoFairwindsOps:masterfrom Apr 23, 2026
Merged
fix: honor -stderrthreshold when -logtostderr is set#850sudermanjr merged 2 commits intoFairwindsOps:masterfrom
sudermanjr merged 2 commits intoFairwindsOps:masterfrom
Conversation
klog v2 defaults -logtostderr to true, which silently causes -stderrthreshold to be ignored. klog v2.140.0 introduced the legacy_stderr_threshold_behavior flag that restores the correct interaction between the two flags (see kubernetes/klog#432). This commit sets legacy_stderr_threshold_behavior=false after klog.InitFlags in cmd/root.go and sets stderrthreshold=INFO so the default behavior is preserved but users can now override it on the command line. Ref: kubernetes/klog#212 Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com> Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
klog v2 defaults
-logtostderrtotrue, which silently causes-stderrthresholdto be ignored — all log messages of every severity are unconditionally written to stderr. There is no way for users to filter which severity levels reach stderr.This has been an open issue since 2020: kubernetes/klog#212.
klog v2.140.0 (kubernetes/klog#432) introduces a
legacy_stderr_threshold_behaviorflag that fixes this. This PR setslegacy_stderr_threshold_behavior=falseafterklog.InitFlagsincmd/root.goand setsstderrthreshold=INFOso the default behavior is preserved but users can now override it on the command line (e.g.-stderrthreshold=WARNING).goldilocks is already on klog v2.140.0, so no dependency bump is needed.
Why it matters
In production clusters, log aggregation systems (Fluentd, Fluent Bit, Loki, Datadog, etc.) typically ingest logs from container stderr. When every log level goes to stderr indiscriminately:
The
-stderrthresholdflag exists precisely to solve this, but it has never worked under the default klog v2 configuration — until now.Changed files
cmd/root.golegacy_stderr_threshold_behavior=false+stderrthreshold=INFOafterklog.InitFlags