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)
| 181 | // We need to manually set the flags from configuration because glog reads |
| 182 | // values from flags, not configuration. |
| 183 | func 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 | |
| 207 | func shellCompletionCmd() *cobra.Command { |
| 208 |