From b1ed1a493f69de13ff1acc9d44edf9d4619a8e70 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Fri, 25 Mar 2022 11:04:55 -0400 Subject: [PATCH] cli log level should override env var log level Signed-off-by: Alex Goodman --- internal/config/application.go | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/internal/config/application.go b/internal/config/application.go index a6f7887..8469237 100644 --- a/internal/config/application.go +++ b/internal/config/application.go @@ -96,18 +96,7 @@ func (cfg *Application) parseConfigValues() error { // ... this will be an enhancement for later cfg.Log.LevelOpt = logrus.PanicLevel } else { - if cfg.Log.Level != "" { - if cfg.CliOptions.Verbosity > 0 { - return fmt.Errorf("cannot explicitly set log level (cfg file or env var) and use -v flag together") - } - - lvl, err := logrus.ParseLevel(strings.ToLower(cfg.Log.Level)) - if err != nil { - return fmt.Errorf("bad log level configured (%q): %w", cfg.Log.Level, err) - } - // set the log level explicitly - cfg.Log.LevelOpt = lvl - } else { + if cfg.CliOptions.Verbosity > 0 { // set the log level implicitly switch v := cfg.CliOptions.Verbosity; { case v == 1: @@ -120,6 +109,13 @@ func (cfg *Application) parseConfigValues() error { cfg.Log.LevelOpt = logrus.WarnLevel } cfg.Log.Level = cfg.Log.LevelOpt.String() + } else { + lvl, err := logrus.ParseLevel(strings.ToLower(cfg.Log.Level)) + if err != nil { + return fmt.Errorf("bad log level configured (%q): %w", cfg.Log.Level, err) + } + // set the log level explicitly + cfg.Log.LevelOpt = lvl } }