CLI - Minor refactoring for aesthetical reasons

This commit is contained in:
Emmanuel BENOîT 2021-02-11 22:31:00 +01:00
parent 4722223603
commit 84fc80bf0a

23
main.go
View file

@ -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() {