Skip to content

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

Merged
sudermanjr merged 2 commits intoFairwindsOps:masterfrom
pierluigilenoci:fix/honor-stderrthreshold
Apr 23, 2026
Merged

fix: honor -stderrthreshold when -logtostderr is set#850
sudermanjr merged 2 commits intoFairwindsOps: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 — 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 cmd/root.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).

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

Why it matters

In production clusters, log aggregation systems (Fluentd, Fluent Bit, Loki, Datadog, etc.) typically ingest logs from container stderr. When every log level goes to stderr indiscriminately:

  • Log storage costs increase — INFO-level debug noise is stored alongside real errors
  • Alerting becomes unreliable — operators cannot trigger alerts on stderr output because it contains everything
  • Signal-to-noise ratio degrades — finding actual errors in a stream of INFO messages is difficult

The -stderrthreshold flag exists precisely to solve this, but it has never worked under the default klog v2 configuration — until now.

Changed files

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

Ref: kubernetes/klog#212

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

@sudermanjr sudermanjr left a comment

Choose a reason for hiding this comment

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

LGTM Thanks

@sudermanjr sudermanjr merged commit b4d579c into FairwindsOps:master Apr 23, 2026
7 checks passed
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