Skip to content

Commit

Permalink
chore: improve logging around unset log level flags
Browse files Browse the repository at this point in the history
previously, if the log level wasn't set via flag, this would fall
through to the default path, which contains strong wording such as
"Failed to parse log level from flag", and setting an `err` field on a
warning level log that calls the value from the flag "unsupported". the
flag is indeed optional, and it feels weird to yell about it. this
addresses that issue by improving logging and handing of the unset flag
case.
  • Loading branch information
tjhop committed Aug 4, 2024
1 parent 5ad969b commit f898f92
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/mango/mango.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ func main() {
// parse log level from flag
logLevelFlagVal := normalizeStringFlag(viper.GetString("logging.level"))
switch logLevelFlagVal {
case "":
logLevel.Set(slog.LevelInfo)
logger.LogAttrs(rootCtx, slog.LevelWarn, "Log level flag not set, defaulting to <info> level")
case "info": // default is info, we're good
case "warn":
logLevel.Set(slog.LevelWarn)
Expand Down

0 comments on commit f898f92

Please sign in to comment.