Skip to content

fix: honor -stderrthreshold even when -logtostderr is true#2017

Open
pierluigilenoci wants to merge 2 commits intoAzure:masterfrom
pierluigilenoci:fix/honor-stderrthreshold
Open

fix: honor -stderrthreshold even when -logtostderr is true#2017
pierluigilenoci wants to merge 2 commits intoAzure:masterfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown
Contributor

What this PR does

klog v2 defaults -logtostderr to true, which silently causes -stderrthreshold to be ignored. This means operators cannot control log severity routing via -stderrthreshold as the flag documentation implies.

klog v2.140.0 introduced the legacy_stderr_threshold_behavior flag to opt into the corrected behavior (see kubernetes/klog#212, kubernetes/klog#432).

This PR:

  1. Bumps k8s.io/klog/v2 from v2.130.1 to v2.140.0
  2. Sets legacy_stderr_threshold_behavior=false and stderrthreshold=INFO after klog.InitFlags(nil) and before flag.Parse(), so that -stderrthreshold is honored as expected

Which issue(s) this PR fixes

Fixes the silent interaction between -logtostderr (default true) and -stderrthreshold documented in kubernetes/klog#212.

Testing

  • go build ./... passes
  • No runtime behavior change for users who do not pass -stderrthreshold (INFO is the default)
  • Users who pass -stderrthreshold=WARNING (or higher) will now correctly see only warnings and above on stderr

Note: This PR was created with the help of AI tools. All changes have been reviewed and validated by the author.

klog v2 defaults -logtostderr to true, which silently causes
-stderrthreshold to be ignored.  klog v2.140.0 introduced the
legacy_stderr_threshold_behavior flag to opt into corrected behavior
(kubernetes/klog#212, kubernetes/klog#432).

Set legacy_stderr_threshold_behavior=false and stderrthreshold=INFO
after klog.InitFlags so operators can control log routing via
-stderrthreshold as expected.

Also bumps k8s.io/klog/v2 from v2.130.1 to v2.140.0.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@pierluigilenoci
Copy link
Copy Markdown
Contributor Author

Hi — friendly ping. Is this PR still on the radar for review? Happy to rebase or make changes if needed. Thanks!

@pierluigilenoci pierluigilenoci marked this pull request as ready for review May 2, 2026 15:34
@pierluigilenoci
Copy link
Copy Markdown
Contributor Author

@aramase — fun fact: this PR finally fixes #387 which was opened 5 years ago! Back then you mentioned that stderrthreshold only works when logs are not printed to stderr. With klog v2.140.0 that limitation is gone — -stderrthreshold is now honored even with -logtostderr=true. The circle closes after 5 years :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant