From 7753213657698f86a512303a6d86489f6cba612f Mon Sep 17 00:00:00 2001 From: LINKIWI Date: Sat, 27 Jan 2024 19:28:43 -0800 Subject: [PATCH] fix: Use zerolog level parser, set global log level correctly from configuration (#724) Former-commit-id: 08b46c2fe32bda46158eac46f82a2341bb1a93c2 --- backend/app/api/logger.go | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/backend/app/api/logger.go b/backend/app/api/logger.go index ddc574f..34659c6 100644 --- a/backend/app/api/logger.go +++ b/backend/app/api/logger.go @@ -2,7 +2,6 @@ package main import ( "os" - "strings" "github.com/hay-kot/homebox/backend/internal/sys/config" "github.com/rs/zerolog" @@ -18,24 +17,8 @@ func (a *app) setupLogger() { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger() } - log.Level(getLevel(a.conf.Log.Level)) -} - -func getLevel(l string) zerolog.Level { - switch strings.ToLower(l) { - case "debug": - return zerolog.DebugLevel - case "info": - return zerolog.InfoLevel - case "warn": - return zerolog.WarnLevel - case "error": - return zerolog.ErrorLevel - case "fatal": - return zerolog.FatalLevel - case "panic": - return zerolog.PanicLevel - default: - return zerolog.InfoLevel + level, err := zerolog.ParseLevel(a.conf.Log.Level) + if err == nil { + zerolog.SetGlobalLevel(level) } }