From 419a1ddd72330dd0dff8d81f8e7034a960fc7e5e Mon Sep 17 00:00:00 2001 From: Cyrille Nofficial Date: Thu, 16 Jun 2022 11:58:43 +0200 Subject: [PATCH] refactor(cli): rewrite log configuration --- cmd/rc-throttle/rc-throttle.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cmd/rc-throttle/rc-throttle.go b/cmd/rc-throttle/rc-throttle.go index 57ce39b..31d56b3 100644 --- a/cmd/rc-throttle/rc-throttle.go +++ b/cmd/rc-throttle/rc-throttle.go @@ -18,7 +18,6 @@ func main() { var mqttBroker, username, password, clientId string var throttleTopic, driveModeTopic, rcThrottleTopic string var minThrottle, maxThrottle float64 - var debug bool err := cli.SetFloat64DefaultValueFromEnv(&minThrottle, "THROTTLE_MIN", DefaultThrottleMin) if err != nil { @@ -39,7 +38,7 @@ func main() { flag.StringVar(&rcThrottleTopic, "mqtt-topic-rc-throttle", os.Getenv("MQTT_TOPIC_RC_THROTTLE"), "Mqtt topic that contains RC Throttle value, use MQTT_TOPIC_RC_THROTTLE if args not set") flag.Float64Var(&minThrottle, "throttle-min", minThrottle, "Minimum throttle value, use THROTTLE_MIN if args not set") flag.Float64Var(&maxThrottle, "throttle-max", maxThrottle, "Minimum throttle value, use THROTTLE_MAX if args not set") - flag.BoolVar(&debug, "debug", false, "Display raw value to debug") + logLevel := zap.LevelFlag("log", zap.InfoLevel, "log level") flag.Parse() if len(os.Args) <= 1 { @@ -48,11 +47,7 @@ func main() { } config := zap.NewDevelopmentConfig() - if debug { - config.Level = zap.NewAtomicLevelAt(zap.DebugLevel) - } else { - config.Level = zap.NewAtomicLevelAt(zap.InfoLevel) - } + config.Level = zap.NewAtomicLevelAt(*logLevel) lgr, err := config.Build() if err != nil { log.Fatalf("unable to init logger: %v", err)