refacto(log): configure log level

This commit is contained in:
Cyrille Nofficial 2022-01-17 18:56:47 +01:00
parent fcfc60ea38
commit 9b5e9c2320

View File

@ -27,7 +27,6 @@ func main() {
var device string var device string
var baud int var baud int
var pubFrequency float64 var pubFrequency float64
var debug bool
mqttQos := cli.InitIntFlag("MQTT_QOS", 0) mqttQos := cli.InitIntFlag("MQTT_QOS", 0)
_, mqttRetain := os.LookupEnv("MQTT_RETAIN") _, mqttRetain := os.LookupEnv("MQTT_RETAIN")
@ -55,20 +54,17 @@ func main() {
flag.IntVar(&steeringLeftPWM, "steering-left-pwm", steeringLeftPWM, "Right left value for steering PWM, STEERING_LEFT_PWM env if args not set") flag.IntVar(&steeringLeftPWM, "steering-left-pwm", steeringLeftPWM, "Right left value for steering PWM, STEERING_LEFT_PWM env if args not set")
flag.IntVar(&steeringRightPWM, "steering-right-pwm", steeringRightPWM, "Right right value for steering PWM, STEERING_RIGHT_PWM env if args not set") flag.IntVar(&steeringRightPWM, "steering-right-pwm", steeringRightPWM, "Right right value for steering PWM, STEERING_RIGHT_PWM env if args not set")
flag.IntVar(&steeringCenterPWM, "steering-center-pwm", steeringCenterPWM, "Center value for steering PWM, STEERING_CENTER_PWM env if args not set") flag.IntVar(&steeringCenterPWM, "steering-center-pwm", steeringCenterPWM, "Center value for steering PWM, STEERING_CENTER_PWM env if args not set")
flag.BoolVar(&debug, "debug", false, "Display raw value to debug")
logLevel := zap.LevelFlag("log", zap.InfoLevel, "log level")
flag.Parse() flag.Parse()
if len(os.Args) <= 1 { if len(os.Args) <= 1 {
flag.PrintDefaults() flag.PrintDefaults()
os.Exit(1) os.Exit(1)
} }
config := zap.NewDevelopmentConfig() config := zap.NewDevelopmentConfig()
if debug { config.Level = zap.NewAtomicLevelAt(*logLevel)
config.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
} else {
config.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
}
lgr, err := config.Build() lgr, err := config.Build()
if err != nil { if err != nil {
log.Fatalf("unable to init logger: %v", err) log.Fatalf("unable to init logger: %v", err)