forked from golang/glog
-
Notifications
You must be signed in to change notification settings - Fork 227
feat: fix stderrthreshold not honored when logtostderr is set (#212) + two new flags #432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
k8s-ci-robot
merged 4 commits into
kubernetes:main
from
pierluigilenoci:fix/stderr-threshold-issue-212
Mar 3, 2026
+464
−30
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
08e6e8b
Fix stderrthreshold not honored when logtostderr is set
pierluigilenoci 2f517bd
Update klog.go
pierluigilenoci 015c613
Update stderr_threshold_test.go
pierluigilenoci 39c4c76
refactor: address code review feedback from @pohly
pierluigilenoci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Example demonstrating the new stderr threshold behavior | ||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
|
|
||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| func main() { | ||
| klog.InitFlags(nil) | ||
| flag.Parse() | ||
|
|
||
| klog.Info("This is an INFO message") | ||
| klog.Warning("This is a WARNING message") | ||
| klog.Error("This is an ERROR message") | ||
|
|
||
| klog.Flush() | ||
| } | ||
|
|
||
| // Run examples: | ||
| // | ||
| // 1. Legacy behavior (default) - all logs to stderr: | ||
| // go run main.go -logtostderr=true -stderrthreshold=ERROR | ||
| // Result: All three messages appear | ||
| // | ||
| // 2. New behavior - filter by severity: | ||
| // go run main.go -logtostderr=true -legacy_stderr_threshold_behavior=false -stderrthreshold=ERROR | ||
| // Result: Only ERROR message appears | ||
| // | ||
| // 3. New behavior - show WARNING and above: | ||
| // go run main.go -logtostderr=true -legacy_stderr_threshold_behavior=false -stderrthreshold=WARNING | ||
| // Result: WARNING and ERROR messages appear | ||
| // | ||
| // 4. Using alsologtostderrthreshold with file logging: | ||
| // go run main.go -logtostderr=false -alsologtostderr=true -alsologtostderrthreshold=ERROR -log_dir=/tmp/logs | ||
| // Result: All logs in files, only ERROR to stderr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.