Skip to content

Commit

Permalink
Do not set nil value for log_backtrace_at flag
Browse files Browse the repository at this point in the history
dgraph-io#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 dgraph-io#3076

Signed-off-by: Ibrahim Jarif <[email protected]>
  • Loading branch information
jarifibrahim committed Feb 28, 2019
1 parent e63279f commit 25764ca
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dgraph/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down

0 comments on commit 25764ca

Please sign in to comment.