slog: use the slog.LevelVar unmarshal to parse log level flag
This commit is contained in:
parent
a9ad981137
commit
defd32b3c8
@ -102,18 +102,13 @@ func createCliApp() *cli.App {
|
|||||||
Value: "INFO",
|
Value: "INFO",
|
||||||
EnvVars: []string{"LOG_LEVEL"},
|
EnvVars: []string{"LOG_LEVEL"},
|
||||||
Action: func(ctx *cli.Context, s string) error {
|
Action: func(ctx *cli.Context, s string) error {
|
||||||
switch s {
|
lvl := new(slog.LevelVar)
|
||||||
case "INFO":
|
err := lvl.UnmarshalText([]byte(s))
|
||||||
slog.SetLogLoggerLevel(slog.LevelInfo)
|
if err != nil {
|
||||||
case "DEBUG":
|
slog.Debug("Error on unmarshal log level flag")
|
||||||
slog.SetLogLoggerLevel(slog.LevelDebug)
|
return err
|
||||||
case "WARN":
|
|
||||||
slog.SetLogLoggerLevel(slog.LevelWarn)
|
|
||||||
case "ERROR":
|
|
||||||
slog.SetLogLoggerLevel(slog.LevelError)
|
|
||||||
default:
|
|
||||||
return cli.Exit(fmt.Sprintf("Undefined log level: %s", s), 1)
|
|
||||||
}
|
}
|
||||||
|
slog.SetLogLoggerLevel(lvl.Level())
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user