From 1b74031793446c0a036780d945aa982a6d790a05 Mon Sep 17 00:00:00 2001 From: Cyrille Nofficial Date: Wed, 29 Dec 2021 18:21:13 +0100 Subject: [PATCH] refacto(log): configure log level --- cmd/rc-led/rc-led.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/cmd/rc-led/rc-led.go b/cmd/rc-led/rc-led.go index 09fe180..9fd2a81 100644 --- a/cmd/rc-led/rc-led.go +++ b/cmd/rc-led/rc-led.go @@ -16,7 +16,6 @@ const ( func main() { var mqttBroker, username, password, clientId string var driveModeTopic, recordTopic string - var debug bool mqttQos := cli.InitIntFlag("MQTT_QOS", 0) _, mqttRetain := os.LookupEnv("MQTT_RETAIN") @@ -26,20 +25,16 @@ func main() { flag.StringVar(&driveModeTopic, "mqtt-topic-drive-mode", os.Getenv("MQTT_TOPIC_DRIVE_MODE"), "Mqtt topic that contains DriveMode value, use MQTT_TOPIC_DRIVE_MODE if args not set") flag.StringVar(&recordTopic, "mqtt-topic-record", os.Getenv("MQTT_TOPIC_RECORD"), "Mqtt topic that contains video recording state, use MQTT_TOPIC_RECORD 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 { flag.PrintDefaults() os.Exit(1) } 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)