From 0b33196f505c26c119ddbefda0df103839d4fadd Mon Sep 17 00:00:00 2001 From: Charlie Tonneslan Date: Sat, 16 May 2026 15:54:54 -0400 Subject: [PATCH] cfg: respect VOUCH_LOGLEVEL when no config file value is set Logging.configure() reset Cfg.LogLevel back to the default whenever viper.IsSet on the config-file key was false. envconfig writes the env-var value straight into Cfg.LogLevel and never goes through viper, so a user who set VOUCH_LOGLEVEL=debug without also putting logLevel in the config file always ended up back on info. Also check the matching env var before overriding so an env-only configuration is honored. The config-file path still wins when both are present, matching the documented precedence. Fixes #540. Signed-off-by: Charlie Tonneslan --- pkg/cfg/logging.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/cfg/logging.go b/pkg/cfg/logging.go index 902eac40..4dda83e8 100644 --- a/pkg/cfg/logging.go +++ b/pkg/cfg/logging.go @@ -103,7 +103,11 @@ func (logging) configure() { } // then we weren't configured via command line, check the config file - if !viper.IsSet(Branding.LCName + ".logLevel") { + // or the matching env var. envconfig writes to Cfg.LogLevel directly + // instead of going through viper, so viper.IsSet on its own wasn't + // enough to detect that the user had asked for a specific level via + // e.g. VOUCH_LOGLEVEL. See #540. + if !viper.IsSet(Branding.LCName+".logLevel") && os.Getenv(Branding.UCName+"_LOGLEVEL") == "" { // then we weren't configured via the config file, set the default Cfg.LogLevel = Logging.DefaultLogLevel.String() }