-
Notifications
You must be signed in to change notification settings - Fork 822
fix: honor -stderrthreshold flag in klog v2 #3086
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,6 +158,13 @@ func InitGOPS() error { | |
| func AddKlogFlags(fs *pflag.FlagSet) { | ||
| local := flag.NewFlagSet("klog", flag.ExitOnError) | ||
| klog.InitFlags(local) | ||
|
|
||
| // Opt into the new klog behavior so that -stderrthreshold is honored even | ||
| // when -logtostderr=true (the default). | ||
| // Ref: kubernetes/klog#212, kubernetes/klog#432 | ||
| _ = local.Set("legacy_stderr_threshold_behavior", "false") | ||
| _ = local.Set("stderrthreshold", "INFO") | ||
|
Comment on lines
+165
to
+166
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The errors returned by if err := local.Set("logtostderr", "false"); err != nil {
klog.Fatalf("failed to set klog logtostderr flag: %v", err)
}
if err := local.Set("legacy_stderr_threshold_behavior", "true"); err != nil {
klog.Fatalf("failed to set klog legacy_stderr_threshold_behavior flag: %v", err)
} |
||
|
|
||
| local.VisitAll(func(fl *flag.Flag) { | ||
| fl.Name = strings.ReplaceAll(fl.Name, "_", "-") | ||
| fs.AddGoFlag(fl) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The errors returned by
local.Setare being ignored. While it's unlikely to fail in this case, it's a good practice to handle errors during application initialization. A failure to set these flags would lead to incorrect logging behavior that could be difficult to debug. Consider checking the error and logging a fatal error if setting the flag fails, to ensure the application exits if it cannot be configured correctly.