From e98ba06e5f643a4494dc03803e5ee289a0507ea6 Mon Sep 17 00:00:00 2001 From: Dennis Adjei-Baah Date: Thu, 7 Feb 2019 13:48:42 -0800 Subject: [PATCH] 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 --- pkg/flags/flags.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/flags/flags.go b/pkg/flags/flags.go index 7f1ddf54b388f..f5f43da91f720 100644 --- a/pkg/flags/flags.go +++ b/pkg/flags/flags.go @@ -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) {