From ec9700a1387d7c87951a52723e088aef255df7fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lilian=20J=C3=B3nsd=C3=B3ttir?= Date: Wed, 24 Jan 2024 17:21:47 -0800 Subject: [PATCH] turns out log already does that I gotta quit writing code before looking at docs ffs --- internal/config/config.go | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 205053f..a9eca03 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -46,7 +46,10 @@ func Initialise() AppConfig { if cfg, err := loadConfig(); err == nil { app.ListenPort = cfg.Port app.UseCache = cfg.UseCache - app.LogLevel = logLevelFromString(cfg.LogLevel) + app.LogLevel, err = log.ParseLevel(cfg.LogLevel) + if err != nil { + app.LogLevel = defaults.LogLevel + } } else { app.Logger.Print("Failed loading config from environment", "err", err) } @@ -66,23 +69,3 @@ func loadConfig() (ConfigDatabase, error) { return cfg, nil } } - -// logLevelFromString turns a string like "warn" into a log.Level like log.WarnLevel -func logLevelFromString(level string) log.Level { - switch level { - case "debug": - return log.DebugLevel - case "info": - return log.InfoLevel - case "warn": - return log.WarnLevel - case "error": - return log.ErrorLevel - case "fatal": - return log.FatalLevel - case "none": - return math.MaxInt32 - default: - return defaults.LogLevel - } -}