From b3d3f4c8698b31ba69c0b14befdc9a064a679bfa Mon Sep 17 00:00:00 2001 From: Chance Zibolski Date: Mon, 9 Mar 2026 15:16:26 -0700 Subject: [PATCH] Improve logging around reading and merging config files Currently viper logs at info level when it attempts to read or merge a config file, and then logs the file it is reading at debug level. When reading multiple files, this means we only get redundant log messages about attempts, but no details about what files are actually being read unless we use debug logs. This patch swaps the log levels so that we get info logs about what files are being read, and debug logs about the attempts. Signed-off-by: Chance Zibolski --- viper.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/viper.go b/viper.go index 2d5158cbd..05a528d31 100644 --- a/viper.go +++ b/viper.go @@ -1580,7 +1580,7 @@ func ReadInConfig() error { return v.ReadInConfig() } // ReadInConfig will discover and load the configuration file from disk // and key/value stores, searching in one of the defined paths. func (v *Viper) ReadInConfig() error { - v.logger.Info("attempting to read in config file") + v.logger.Debug("attempting to read in config file") filename, err := v.getConfigFile() if err != nil { return err @@ -1590,7 +1590,7 @@ func (v *Viper) ReadInConfig() error { return UnsupportedConfigError(v.getConfigType()) } - v.logger.Debug("reading file", "file", filename) + v.logger.Info("reading file", "file", filename) file, err := afero.ReadFile(v.fs, filename) if errors.Is(err, fs.ErrNotExist) { @@ -1617,7 +1617,7 @@ func MergeInConfig() error { return v.MergeInConfig() } // MergeInConfig merges a new configuration with an existing config. func (v *Viper) MergeInConfig() error { - v.logger.Info("attempting to merge in config file") + v.logger.Debug("attempting to merge in config file") filename, err := v.getConfigFile() if err != nil { return err @@ -1627,6 +1627,8 @@ func (v *Viper) MergeInConfig() error { return UnsupportedConfigError(v.getConfigType()) } + v.logger.Info("merging file into config", "file", filename) + file, err := afero.ReadFile(v.fs, filename) if err != nil { return err