Skip to content

Honor stderrthreshold when logtostderr is enabled#354

Closed
pierluigilenoci wants to merge 1 commit into
nats-io:mainfrom
pierluigilenoci:fix/honor-stderrthreshold-v2
Closed

Honor stderrthreshold when logtostderr is enabled#354
pierluigilenoci wants to merge 1 commit into
nats-io:mainfrom
pierluigilenoci:fix/honor-stderrthreshold-v2

Conversation

@pierluigilenoci

Copy link
Copy Markdown
Contributor

Summary

Opt into the new klog v2.140.0 behavior so that -stderrthreshold is honored even when -logtostderr=true (the default). This fixes the long-standing klog bug (kubernetes/klog#212) where the stderrthreshold flag was silently ignored.

Changes

  • Bump k8s.io/klog/v2 from v2.130.1 to v2.140.0
  • Set legacy_stderr_threshold_behavior=false and stderrthreshold=INFO programmatically after klog.InitFlags(nil)
  • No behavior change by default: With the default --stderrthreshold=INFO, all log levels still go to stderr as before
  • New capability: Users can now set --stderrthreshold=WARNING (or ERROR) to actually filter out lower-severity messages from stderr

References

Supersedes #352 (recreated to fix CI checkout issue with fork branches).

@synadia-claude-reviewer

Copy link
Copy Markdown

Claude Code is working…

I'll analyze this and get back to you.

View job run

When logtostderr is true (the default), klog historically ignored
stderrthreshold, silently dropping log messages that should have been
written to stderr.

This was fixed in klog v2.140.0 by introducing a new flag
legacy_stderr_threshold_behavior. Setting it to false makes klog
honour stderrthreshold regardless of logtostderr.

This PR opts into the fixed behavior by calling:
  flag.Set("legacy_stderr_threshold_behavior", "false")
  flag.Set("stderrthreshold", "INFO")

right after klog.InitFlags(nil), so that all severity levels above
INFO are still printed to stderr by default but operators can now
filter using --stderrthreshold.

Ref: kubernetes/klog#212, kubernetes/klog#432

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
@pierluigilenoci pierluigilenoci force-pushed the fix/honor-stderrthreshold-v2 branch from 2df1ba3 to 32317f8 Compare April 10, 2026 10:12
@pierluigilenoci

Copy link
Copy Markdown
Contributor Author

Hi @wallyqs @Jarema @samuelattwood — this PR has been rebased and is ready for review. It's a small fix to honor the stderrthreshold klog flag, ensuring log messages respect the configured threshold instead of always going to stderr.

Would you be able to take a look when you get a chance? Happy to address any feedback. Thank you!

@pierluigilenoci

Copy link
Copy Markdown
Contributor Author

Hi @Jarema — friendly ping on this PR. It fixes the klog stderrthreshold behavior when logtostderr is enabled. Happy to address any feedback. Thanks!

@pierluigilenoci

Copy link
Copy Markdown
Contributor Author

Closing in favor of #360, which addresses the same fix with a cleaner approach and has been approved by a maintainer. Thank you!

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