CLI - Minor refactoring for aesthetical reasons
This commit is contained in:
parent
4722223603
commit
84fc80bf0a
1 changed files with 9 additions and 14 deletions
23
main.go
23
main.go
|
@ -45,27 +45,22 @@ func getLoggingContext(instance string) *logrus.Entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the log level
|
// Configure the log level
|
||||||
func configureLogLevel(cliLevel string) {
|
func toLogLevel(cliLevel string) logrus.Level {
|
||||||
var lvl logrus.Level
|
|
||||||
if cliLevel == "" {
|
if cliLevel == "" {
|
||||||
lvl = logrus.InfoLevel
|
return logrus.InfoLevel
|
||||||
} else {
|
|
||||||
var err error
|
|
||||||
lvl, err = logrus.ParseLevel(cliLevel)
|
|
||||||
if err != nil {
|
|
||||||
log.WithFields(logrus.Fields{
|
|
||||||
"level": cliLevel,
|
|
||||||
}).Warning("Invalid log level on command line")
|
|
||||||
lvl = logrus.InfoLevel
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
log.Logger.SetLevel(lvl)
|
lvl, err := logrus.ParseLevel(cliLevel)
|
||||||
|
if err == nil {
|
||||||
|
return lvl
|
||||||
|
}
|
||||||
|
log.WithField("level", cliLevel).Warning("Invalid log level on command line")
|
||||||
|
return logrus.InfoLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the logging library based on the various command line flags.
|
// Configure the logging library based on the various command line flags.
|
||||||
func configureLogging(flags cliFlags) {
|
func configureLogging(flags cliFlags) {
|
||||||
log = getLoggingContext(flags.instance)
|
log = getLoggingContext(flags.instance)
|
||||||
configureLogLevel(flags.logLevel)
|
log.Logger.SetLevel(toLogLevel(flags.logLevel))
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
Loading…
Reference in a new issue