Skip to content

Honor stderrthreshold when logtostderr is enabled#646

Open
pierluigilenoci wants to merge 1 commit intocontainers:mainfrom
pierluigilenoci:fix/honor-stderrthreshold
Open

Honor stderrthreshold when logtostderr is enabled#646
pierluigilenoci wants to merge 1 commit intocontainers:mainfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown

Summary

  • After klog.InitFlags, opt into the fixed stderrthreshold behavior introduced in klog v2.140.0
  • Bump k8s.io/klog/v2 from v2.130.1 to v2.140.0
  • Applied to pkg/log/klogcontrol/klogcontrol.go (the init function that configures klog flags)

Motivation

When logtostderr is enabled (the default), klog historically suppressed the stderrthreshold flag, meaning that WARNING and ERROR messages could not be selectively filtered. klog v2.140.0 introduced new flags (legacy_stderr_threshold_behavior) to opt into the corrected behavior where stderrthreshold is properly honored.

Reference: kubernetes/klog#212

Test plan

  • Verify the application still logs to stderr as expected
  • Confirm stderrthreshold flag can be used to control which severity levels appear on stderr

After calling klog.InitFlags, opt into the fixed stderrthreshold
behavior added in klog v2.140.0 so that severe-enough messages are
still mirrored to stderr when logtostderr is set.

Reference: kubernetes/klog#212
Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
@pierluigilenoci
Copy link
Copy Markdown
Author

cc @klihub @fmuyassarov for review

Copy link
Copy Markdown
Collaborator

@klihub klihub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pierluigilenoci Thank you ! LGTM.

Is it so that all the dynamic controls we might exercise over klog when our configuration CR changes still works as before with the updated klog ?

@pierluigilenoci
Copy link
Copy Markdown
Author

@klihub Thanks for the review and great question!

Yes, all dynamic controls over klog still work exactly as before. The legacy_stderr_threshold_behavior=false flag only changes how the stderrthreshold flag is interpreted at startup — it makes klog respect the configured threshold value instead of using a hardcoded legacy default.

Any runtime changes to klog verbosity levels (via klog.V() settings, flag changes, or your configuration CR) are unaffected. The flag is purely about the initial stderr threshold behavior, not about the dynamic control mechanism itself.

In short: this is a one-time startup flag that fixes the default behavior; all dynamic reconfiguration paths remain unchanged.

@klihub klihub requested a review from fmuyassarov March 27, 2026 16:32
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.

2 participants