MCPcopy
hub / github.com/dgraph-io/dgraph / setGlogFlags

Function setGlogFlags

dgraph/cmd/root.go:183–205  ·  view source on GitHub ↗

setGlogFlags function sets the glog flags based on the configuration. We need to manually set the flags from configuration because glog reads values from flags, not configuration.

(conf *viper.Viper)

Source from the content-addressed store, hash-verified

181// We need to manually set the flags from configuration because glog reads
182// values from flags, not configuration.
183func setGlogFlags(conf *viper.Viper) {
184 // List of flags taken from
185 // https://github.com/golang/glog/blob/master/glog.go#L399
186 // and https://github.com/golang/glog/blob/master/glog_file.go#L41
187 glogFlags := [...]string{
188 "log_dir", "logtostderr", "alsologtostderr", "v",
189 "stderrthreshold", "vmodule", "log_backtrace_at",
190 }
191 for _, gflag := range glogFlags {
192 // Set value of flag to the value in config
193 stringValue := conf.GetString(gflag)
194 // Special handling for log_backtrace_at flag because the flag is of
195 // type tracelocation. The nil value for tracelocation type is
196 // ":0"(See https://github.com/golang/glog/blob/master/glog.go#L322).
197 // But we can't set nil value for the flag because of
198 // https://github.com/golang/glog/blob/master/glog.go#L374
199 // Skip setting value if log_backstrace_at is nil in config.
200 if gflag == "log_backtrace_at" && (stringValue == "0" || stringValue == ":0") {
201 continue
202 }
203 x.Check(flag.Lookup(gflag).Value.Set(stringValue))
204 }
205}
206
207func shellCompletionCmd() *cobra.Command {
208

Callers 1

initCmdsFunction · 0.85

Calls 2

CheckFunction · 0.92
SetMethod · 0.65

Tested by

no test coverage detected