Modify klog to be verbose when controller log-level is set to debug#2221
Modify klog to be verbose when controller log-level is set to debug#2221dadjeibaah merged 2 commits intomasterfrom
Conversation
Signed-off-by: Dennis Adjei-Baah <[email protected]>
pkg/flags/flags.go
Outdated
| klog.InitFlags(nil) | ||
| flag.Set("logtostderr", "true") | ||
| // -stderrthreshold=FATAL forces klog to only log FATAL errors to stderr. | ||
| // -logtostderr to false to not log to stderr by default. |
There was a problem hiding this comment.
You'll want to set -v to 0 here as well.
pkg/flags/flags.go
Outdated
| } | ||
| log.SetLevel(level) | ||
|
|
||
| klog.SetOutput(ioutil.Discard) |
There was a problem hiding this comment.
No reason to do this. But you will want to set the log file to /dev/null.
There was a problem hiding this comment.
While working on this I found that any flags that were set in this method would not have any effect on the logs because we would be modifying flags after flags.Parse() was called. So setting the log_file to /dev/null would not work here. Setting the output to ioutil.DIscardseemed to work.
There was a problem hiding this comment.
Looks like it is because you created the second flag set. This works:
func ConfigureAndParse() {
// -stderrthreshold=FATAL forces klog to only log FATAL errors to stderr.
// -logtostderr to false to not log to stderr by default.
klog.InitFlags(nil)
flag.Set("stderrthreshold", "FATAL")
flag.Set("logtostderr", "false")
flag.Set("log_file", "/dev/null")
flag.Set("v", "0")
logLevel := flag.String("log-level", log.InfoLevel.String(),
"log level, must be one of: panic, fatal, error, warn, info, debug")
printVersion := flag.Bool("version", false, "print version and exit")
flag.Parse()
setLogLevel(*logLevel)
maybePrintVersionAndExit(*printVersion)
}
func setLogLevel(logLevel string) {
level, err := log.ParseLevel(logLevel)
if err != nil {
log.Fatalf("invalid log-level: %s", logLevel)
}
log.SetLevel(level)
// Anything lower than the INFO level according to log is sent to /dev/null
if level == log.DebugLevel {
flag.Set("stderrthreshold", "INFO")
flag.Set("logtostderr", "true")
flag.Set("v", "10")
}
}There was a problem hiding this comment.
This is awesome! Thanks! 👍
pkg/flags/flags.go
Outdated
| // Anything lower than the INFO level according to log is sent to /dev/null | ||
| if level == log.DebugLevel { | ||
| // Set stderr to INFO severity see https://github.com/kubernetes/klog/issues/23 | ||
| klog.SetOutputBySeverity("INFO", os.Stderr) |
There was a problem hiding this comment.
Don't forget a -v of 8 or 10.
pkg/flags/flags.go
Outdated
| // Anything lower than the INFO level according to log is sent to /dev/null | ||
| if level == log.DebugLevel { | ||
| // Set stderr to INFO severity see https://github.com/kubernetes/klog/issues/23 | ||
| klog.SetOutputBySeverity("INFO", os.Stderr) |
There was a problem hiding this comment.
Just -stderrthreshold to info and that's good enough.
There was a problem hiding this comment.
Same deal here as my previous comment pointed out.
Signed-off-by: Dennis Adjei-Baah <[email protected]>
klingerf
left a comment
There was a problem hiding this comment.
⭐️ 🚀 Great, this will be a huge improvement for our controller pods.
| if level == log.DebugLevel { | ||
| flag.Set("stderrthreshold", "INFO") | ||
| flag.Set("logtostderr", "true") | ||
| flag.Set("v", "10") |
There was a problem hiding this comment.
TIL you can call flag.Set after flag.Parse and it will still work. I wasn't expecting that, but have verified that this implementation does what you want it to do.
There was a problem hiding this comment.
Honestly, it frightens me a little bit. There be dragons there =)
The controller logs innocuous messages when control plane proxies aren't ready to route requests during startup from each control plane component. i.e. tap, public-api and proxy-api. Setting the log level in the control plane to
INFOwould not hide these log messages and would still show up on control plane startup.This PR modifies
klogsinitial flag set to route innocuous logs to/dev/nullif the controller log level is set to INFO. If set to debug, we output all loglines to stderr.Fixes #2171 #2168
Signed-off-by: Dennis Adjei-Baah [email protected]