fix: honor klog -stderrthreshold even when -logtostderr is true#164
Merged
johnjeffers merged 2 commits intoApr 24, 2026
Merged
Conversation
klog v2 defaults -logtostderr to true, which silently ignores -stderrthreshold — all log levels go to stderr unconditionally. This has been an open issue since 2020 (kubernetes/klog#212). klog v2.140.0 introduced a fix behind an opt-in flag (legacy_stderr_threshold_behavior). This commit enables the fix so that -stderrthreshold is honored, while preserving the current default behavior (stderrthreshold=INFO means all logs still go to stderr unless the user overrides it on the command line). Ref: kubernetes/klog#212 Ref: kubernetes/klog#432 Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
johnjeffers
reviewed
Apr 24, 2026
| klogFlags.Set("legacy_stderr_threshold_behavior", "false") | ||
| klogFlags.Set("stderrthreshold", "INFO") | ||
| klogFlags.Set("logtostderr", "true") | ||
| klogFlags.Set("stderrthreshold", "0") |
Collaborator
There was a problem hiding this comment.
Should probably remove either this line or line 75, since they appear to do the same thing.
Contributor
Author
There was a problem hiding this comment.
Good catch — the "INFO" form on line 75 and the numeric "0" on line 77 resolve to the same klog severity, so the second set was a leftover from the original code that I forgot to remove when I added the named constant. Removed the duplicate in 4a18301.
The "INFO" string form (line 75) and the numeric "0" form were both setting the same klog severity level. Keep the human-readable "INFO" that sits next to the explanatory comment and drop the redundant "0". Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com> Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
johnjeffers
approved these changes
Apr 24, 2026
Collaborator
|
@pierluigilenoci thank you for the contribution! This will go out in v1.6.2, likely later today, possibly tomorrow. |
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 changed
klog v2 defaults
-logtostderrtotrue, which silently ignores-stderrthreshold— all log levels go to stderr unconditionally. This has been an open issue since 2020.klog v2.140.0 (already in use by this project) introduced a fix behind an opt-in flag (
legacy_stderr_threshold_behavior). This PR enables the fix inbackend/internal/errorcapture/error_capture.goso that thestderrthresholdsetting is actually honored when-logtostderr=true.What the fix does
The fix is backward-compatible and preserves the current stderr capture behavior.
References