Skip to content

fix: honor stderrthreshold by disabling logtostderr default#2230

Merged
csatib02 merged 2 commits intokube-logging:masterfrom
pierluigilenoci:fix/honor-stderrthreshold
Apr 25, 2026
Merged

fix: honor stderrthreshold by disabling logtostderr default#2230
csatib02 merged 2 commits intokube-logging:masterfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci
Copy link
Copy Markdown
Contributor

What this PR does

klog v2 defaults -logtostderr=true, which silently ignores -stderrthreshold. This means that even when operators or users set -stderrthreshold to control log routing, it has no effect.

This PR adds two flag.Set calls immediately after klog.InitFlags() in main.go:

  1. logtostderr=false — disables the default that suppresses stderrthreshold
  2. legacy_stderr_threshold_behavior=true — opts in to the fix introduced in klog v2.140.0 that restores correct stderrthreshold semantics

The project already depends on klog v2.140.0, so no dependency changes are needed.

Which issue(s) this PR fixes

Related upstream fix: kubernetes/klog#432

Notes for reviewers

  • The fix follows the same klogFlags.Set(...) pattern already used on the next line for the "v" flag
  • No new dependencies introduced
  • This is a minimal, targeted change

Disclosure: This PR was authored with AI assistance.

klog v2 defaults -logtostderr=true, which silently ignores
-stderrthreshold. This adds flag.Set calls after klog.InitFlags()
to disable logtostderr and enable legacy_stderr_threshold_behavior,
a flag introduced in klog v2.140.0 (kubernetes/klog#432).

This ensures that -stderrthreshold works as expected when configured.

Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@promptless-for-oss
Copy link
Copy Markdown

Promptless prepared a documentation update related to this change.

Triggered by this PR

Added documentation for the -stderrthreshold flag to the "Operator arguments" section now that it works correctly with this fix. Users can now control which log severity levels (INFO=0, WARNING=1, ERROR=2, FATAL=3) are written to stderr.

Review: Document stderrthreshold flag

Set legacy_stderr_threshold_behavior=false (not true) to enable the fix,
and set stderrthreshold=INFO (not logtostderr=false) to preserve default
behavior while allowing users to override on the command line.

Signed-off-by: Pierluigi Lenoci <pierluigi.lenoci@gmail.com>
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@csatib02 csatib02 merged commit 8588c1d into kube-logging:master Apr 25, 2026
29 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.

4 participants