diff --git a/cmd/federation.go b/cmd/federation.go index d845fed..e8c2f17 100644 --- a/cmd/federation.go +++ b/cmd/federation.go @@ -27,6 +27,11 @@ func main() { wg := &sync.WaitGroup{} // bootstrap logger + logLevel, ok := os.LookupEnv("LOG_LEVEL") + if !ok { + logLevel = "info" + } + log.SetGlobalLevel(logLevel) logger := log.NewLogger("main") // Load connection string from .env file diff --git a/internal/log/log.go b/internal/log/log.go index 65bbfda..ef5185b 100644 --- a/internal/log/log.go +++ b/internal/log/log.go @@ -6,6 +6,7 @@ import ( "io" "net/http" "os" + "strings" "github.com/rs/zerolog" ) @@ -29,6 +30,23 @@ func NewLogger(name string) *Log { return &Log{&logger} } +func SetGlobalLevel(level string) { + switch strings.ToLower(level) { + case "disabled": + zerolog.SetGlobalLevel(zerolog.Disabled) + case "error": + zerolog.SetGlobalLevel(zerolog.ErrorLevel) + case "warning": + zerolog.SetGlobalLevel(zerolog.WarnLevel) + case "info": + zerolog.SetGlobalLevel(zerolog.InfoLevel) + case "debug": + zerolog.SetGlobalLevel(zerolog.DebugLevel) + default: + zerolog.SetGlobalLevel(zerolog.InfoLevel) + } +} + func (logger *Log) Info(msg string) { logger.Logger.Info().Msg(msg) }