Skip to content

fix: honor -stderrthreshold when -logtostderr is set#4903

Closed
pierluigilenoci wants to merge 1 commit intocilium:mainfrom
pierluigilenoci:fix/honor-stderrthreshold
Closed

fix: honor -stderrthreshold when -logtostderr is set#4903
pierluigilenoci wants to merge 1 commit intocilium:mainfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown

What this PR does

klog v2 defaults -logtostderr to true, which silently causes -stderrthreshold to 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_behavior flag that fixes this. This PR sets legacy_stderr_threshold_behavior=false after klog.InitFlags in pkg/logger/klog_bridge.go and sets stderrthreshold=INFO so the default behavior is preserved but users can now override it on the command line (e.g. -stderrthreshold=WARNING).

Tetragon is already on klog v2.140.0, so no dependency bump is needed.

Why it matters

While Tetragon's custom logging setup already routes klog output by severity via SetOutputBySeverity, this change ensures the klog-internal stderrthreshold mechanism works correctly as a defense-in-depth measure. In production clusters, log aggregation systems (Fluentd, Fluent Bit, Loki, Datadog, etc.) benefit from proper severity filtering at the klog level.

Changed files

File Change
pkg/logger/klog_bridge.go set legacy_stderr_threshold_behavior=false + stderrthreshold=INFO after klog.InitFlags

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 pkg/logger/klog_bridge.go and sets
stderrthreshold=INFO so the default behavior is preserved but
users can now override it on the command line.

Tetragon is already on klog v2.140.0 so no dependency bump is
needed.

Ref: kubernetes/klog#212

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

FedeDP commented Apr 24, 2026

Hi!
Isn't this exactly the same of #4805 that was closed as not needed?

@pierluigilenoci
Copy link
Copy Markdown
Author

Apologies — I missed that #4805 had already been submitted and closed. I mistakenly believed I hadn't opened a PR for this repository yet. Closing this as a duplicate.

Sorry for the noise.

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