Modify klog to be verbose when controller log-level is set to debug (#2221)

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 `INFO` would not hide these log messages and would still show up on control plane startup.

This PR modifies `klogs` initial flag set to route innocuous logs to `/dev/null` if 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 <dennis@buoyant.io>
This commit is contained in:
Dennis Adjei-Baah 2019-02-07 13:48:42 -08:00 committed by GitHub
parent 74eac764d8
commit e98ba06e5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -14,10 +14,11 @@ import (
// func calls flag.Parse(), so it should be called after all other flags have
// been configured.
func ConfigureAndParse() {
// override klog's default configuration and log to stderr instead of a file
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
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")
@ -34,6 +35,12 @@ func setLogLevel(logLevel string) {
log.Fatalf("invalid log-level: %s", logLevel)
}
log.SetLevel(level)
if level == log.DebugLevel {
flag.Set("stderrthreshold", "INFO")
flag.Set("logtostderr", "true")
flag.Set("v", "10")
}
}
func maybePrintVersionAndExit(printVersion bool) {