Skip to content

fix: honor klog -stderrthreshold even when -logtostderr is true#695

Merged
marcushines merged 1 commit into
openconfig:mainfrom
pierluigilenoci:fix/honor-stderrthreshold
Jun 25, 2026
Merged

fix: honor klog -stderrthreshold even when -logtostderr is true#695
marcushines merged 1 commit into
openconfig:mainfrom
pierluigilenoci:fix/honor-stderrthreshold

Conversation

@pierluigilenoci

Copy link
Copy Markdown
Contributor

What changed

klog v2 defaults -logtostderr to true, which silently ignores -stderrthreshold — all log levels go to stderr unconditionally. This has been an open issue since 2020.

klog v2.140.0 introduced a fix behind an opt-in flag (legacy_stderr_threshold_behavior). This PR bumps klog to v2.140.0 and enables the fix in flags/flags.go so that -stderrthreshold is honored, while preserving the current default behavior (stderrthreshold=INFO means all logs still go to stderr unless the user explicitly overrides it on the command line).

What the fix does

klog.InitFlags(nil)
flag.Set("legacy_stderr_threshold_behavior", "false") // enable the klog fix
flag.Set("stderrthreshold", "INFO")                   // preserve current default

Since the Import() function applies caller-provided defaults after InitFlags, any project-level overrides via defmap continue to work as before.

References

@pierluigilenoci

Copy link
Copy Markdown
Contributor Author

Hi, the kne-presubmit check is pending with "Needs /gcbrun from a collaborator". Could a maintainer please run /gcbrun when convenient? Thanks!

@pierluigilenoci

Copy link
Copy Markdown
Contributor Author

Hi — gentle reminder. The kne-presubmit check is pending with "Needs /gcbrun from a collaborator." Could a maintainer please run /gcbrun when convenient? Thanks!

@pierluigilenoci

Copy link
Copy Markdown
Contributor Author

Hi — friendly follow-up. Could a collaborator run /gcbrun to trigger the presubmit check? The code change is minimal (klog flag configuration) and all other checks pass. Thank you!

@pierluigilenoci

Copy link
Copy Markdown
Contributor Author

Hi — gentle ping on this PR. The kne-presubmit (kne-external) check is still waiting on /gcbrun from a collaborator. Could someone run it when convenient? The code change is minimal (klog flag configuration). Thank you!

@pierluigilenoci pierluigilenoci force-pushed the fix/honor-stderrthreshold branch from c4a760f to 4565edc Compare June 17, 2026 21:49
@pierluigilenoci

Copy link
Copy Markdown
Contributor Author

Hi — just a quick ping on the CI status. The go / lint failure was due to a runner receiving a shutdown signal mid-run (not an actual lint error — golangci-lint never finished). The kne-presubmit (kne-external) check is waiting on /gcbrun from a collaborator.

Could a maintainer run /gcbrun to trigger the presubmit check? The change is minimal (klog flag initialization) and all other checks pass. Thank you!

@pierluigilenoci pierluigilenoci force-pushed the fix/honor-stderrthreshold branch from 4565edc to 45c10f8 Compare June 25, 2026 12:14
klog v2 defaults -logtostderr to true, which silently ignores
-stderrthreshold — all log levels go to stderr unconditionally.
This has been an open issue since 2020 (kubernetes/klog#212).

klog v2.140.0 introduced a fix behind an opt-in flag
(legacy_stderr_threshold_behavior). This commit bumps klog to
v2.140.0 and enables the fix so that -stderrthreshold is honored,
while preserving the current default behavior (stderrthreshold=INFO
means all logs still go to stderr unless the user overrides it on
the command line).

Ref: kubernetes/klog#212
Ref: kubernetes/klog#432
Signed-off-by: Pierluigi Lenoci <pierluigilenoci@gmail.com>
@marcushines marcushines force-pushed the fix/honor-stderrthreshold branch from 45c10f8 to 36a87f6 Compare June 25, 2026 18:21
@marcushines

Copy link
Copy Markdown
Contributor

/gcbrun

@marcushines marcushines merged commit 9e1b3b7 into openconfig:main Jun 25, 2026
11 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