From 25764ca49947636c42235ed9f616a0cbb1f2de89 Mon Sep 17 00:00:00 2001 From: Ibrahim Jarif Date: Fri, 1 Mar 2019 01:49:08 +0530 Subject: [PATCH] Do not set nil value for log_backtrace_at flag https://github.com/dgraph-io/dgraph/pull/3062 added capabilities to set flag values from config file (we need this for glog). This caused an issue with the log_backtrace_at flag. The flag is defined as `flag.Var(&logging.traceLocation, "log_backtrace_at", "when logging hits line file:N, emit a stack trace")` where tracelocation is ``` // traceLocation represents the setting of the -log_backtrace_at flag. type traceLocation struct { file string line int } ``` If the value isn't specified the nil value for tracelocation type is set in the config, which is tracelocation{"", 0}. But this value can't be set to the flag because of the check on line https://github.com/golang/glog/blob/master/glog.go#L374 This PR adds skips setting the flag to nil value if it nil in the config. Fixes https://github.com/dgraph-io/dgraph/issues/3076 Signed-off-by: Ibrahim Jarif --- dgraph/cmd/root.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dgraph/cmd/root.go b/dgraph/cmd/root.go index 453c81cb9c9..faefed53a36 100644 --- a/dgraph/cmd/root.go +++ b/dgraph/cmd/root.go @@ -132,6 +132,14 @@ func setGlogFlags(conf *viper.Viper) { for _, gflag := range glogFlags { // Set value of flag to the value in config if stringValue, ok := conf.Get(gflag).(string); ok { + // Special handling for log_backtrace_at flag because the flag is of + // type tracelocation. The nil value for default tracelocation is + // ":0"(See https://github.com/golang/glog/blob/master/glog.go#L322). + // But we can't set nil value for the flag because of + // https://github.com/golang/glog/blob/master/glog.go#L374 + if gflag == "log_backtrace_at" && stringValue == ":0" { + continue + } x.Check(flag.Lookup(gflag).Value.Set(stringValue)) } }