From f898f92c8beb005f74a1555300faf56950976719 Mon Sep 17 00:00:00 2001 From: TJ Hoplock Date: Sun, 4 Aug 2024 00:16:08 -0400 Subject: [PATCH] chore: improve logging around unset log level flags 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. --- cmd/mango/mango.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/mango/mango.go b/cmd/mango/mango.go index bf908e9..22dc298 100644 --- a/cmd/mango/mango.go +++ b/cmd/mango/mango.go @@ -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 level") case "info": // default is info, we're good case "warn": logLevel.Set(slog.LevelWarn)