You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix stderrthreshold not honored when logtostderr is set
Add two new flags to allow severity filtering with logtostderr while
maintaining full backward compatibility:
- legacy_stderr_threshold_behavior (default: true): Controls whether
stderrthreshold is honored when logtostderr=true
- alsologtostderrthreshold (default: INFO): Provides filtering control
when alsologtostderr=true
This fix allows users to opt-in to severity filtering when logging to
stderr, addressing a long-standing issue where all logs would be written
to stderr regardless of severity level.
The default behavior remains unchanged for backward compatibility.
Ref: #212
"If the value is 0, the maximum file size is unlimited.")
417
429
commandLine.BoolVar(&logging.toStderr, "logtostderr", true, "log to standard error instead of files")
418
430
commandLine.BoolVar(&logging.alsoToStderr, "alsologtostderr", false, "log to standard error as well as files (no effect when -logtostderr=true)")
431
+
commandLine.BoolVar(&logging.legacyStderrThresholdBehavior, "legacy_stderr_threshold_behavior", true, "If true, stderrthreshold is ignored when logtostderr=true (legacy behavior). If false, stderrthreshold is honored even when logtostderr=true")
419
432
logging.setVState(0, nil, false)
420
433
commandLine.Var(&logging.verbosity, "v", "number for the log level verbosity")
421
434
commandLine.BoolVar(&logging.addDirHeader, "add_dir_header", false, "If true, adds the file directory to the header of the log messages")
@@ -425,7 +438,11 @@ func init() {
425
438
logging.stderrThreshold=severityValue{
426
439
Severity: severity.ErrorLog, // Default stderrThreshold is ERROR.
427
440
}
428
-
commandLine.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=true)")
441
+
commandLine.Var(&logging.stderrThreshold, "stderrthreshold", "logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=true unless -legacy_stderr_threshold_behavior=false)")
442
+
logging.alsologtostderrthreshold=severityValue{
443
+
Severity: severity.InfoLog, // Default alsologtostderrthreshold is INFO (to maintain backward compatibility).
444
+
}
445
+
commandLine.Var(&logging.alsologtostderrthreshold, "alsologtostderrthreshold", "logs at or above this threshold go to stderr when -alsologtostderr=true (no effect when -logtostderr=true)")
429
446
commandLine.Var(&logging.vmodule, "vmodule", "comma-separated list of pattern=N settings for file-filtered logging")
430
447
commandLine.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")
431
448
@@ -470,11 +487,13 @@ type settings struct {
470
487
// Boolean flags. Not handled atomically because the flag.Value interface
471
488
// does not let us avoid the =true, and that shorthand is necessary for
472
489
// compatibility. TODO: does this matter enough to fix? Seems unlikely.
473
-
toStderrbool// The -logtostderr flag.
474
-
alsoToStderrbool// The -alsologtostderr flag.
490
+
toStderrbool// The -logtostderr flag.
491
+
alsoToStderrbool// The -alsologtostderr flag.
492
+
legacyStderrThresholdBehaviorbool// The -legacy_stderr_threshold_behavior flag.
475
493
476
494
// Level flag. Handled atomically.
477
-
stderrThresholdseverityValue// The -stderrthreshold flag.
495
+
stderrThresholdseverityValue// The -stderrthreshold flag.
496
+
alsologtostderrthresholdseverityValue// The -alsologtostderrthreshold flag.
478
497
479
498
// Access to all of the following fields must be protected via a mutex.
If true, adds the file directory to the header of the log messages
945
945
-alsologtostderr
946
946
log to standard error as well as files (no effect when -logtostderr=true)
947
+
-alsologtostderrthreshold value
948
+
logs at or above this threshold go to stderr when -alsologtostderr=true (no effect when -logtostderr=true)
949
+
-legacy_stderr_threshold_behavior
950
+
If true, stderrthreshold is ignored when logtostderr=true (legacy behavior). If false, stderrthreshold is honored even when logtostderr=true (default true)
If true, avoid headers when opening log files (no effect when -logtostderr=true)
963
967
-stderrthreshold value
964
-
logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=true) (default 2)
968
+
logs at or above this threshold go to stderr when writing to files and stderr (no effect when -logtostderr=true or -alsologtostderr=true unless -legacy_stderr_threshold_behavior=false) (default 2)
0 commit comments