Skip to content

Commit

Permalink
Modify klog to be verbose when controller log-level is set to debug (l…
Browse files Browse the repository at this point in the history
…inkerd#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 linkerd#2171 linkerd#2168
Signed-off-by: Dennis Adjei-Baah <dennis@buoyant.io>
  • Loading branch information
Dennis Adjei-Baah authored Feb 7, 2019
1 parent 74eac76 commit e98ba06
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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) {
Expand Down

0 comments on commit e98ba06

Please sign in to comment.