refactor(log): zap/flag integration

This commit is contained in:
Cyrille Nofficial 2021-12-18 17:57:31 +01:00
parent 4c3954ec76
commit 05a0af6b74

View File

@ -21,8 +21,6 @@ func main() {
var modelPath string var modelPath string
var edgeVerbosity int var edgeVerbosity int
var imgWidth, imgHeight, horizon int var imgWidth, imgHeight, horizon int
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")
@ -36,20 +34,16 @@ func main() {
flag.IntVar(&imgWidth, "img-width", 0, "image width expected by model (mandatory)") flag.IntVar(&imgWidth, "img-width", 0, "image width expected by model (mandatory)")
flag.IntVar(&imgHeight, "img-height", 0, "image height expected by model (mandatory)") flag.IntVar(&imgHeight, "img-height", 0, "image height expected by model (mandatory)")
flag.IntVar(&horizon, "horizon", 0, "upper zone to crop from image. Models expect size 'imgHeight - horizon'") flag.IntVar(&horizon, "horizon", 0, "upper zone to crop from image. Models expect size 'imgHeight - horizon'")
flag.BoolVar(&debug, "debug", false, "Display debug logs") 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)