From 4906505d026cc8ea8187224606bafc59d1ab3ba3 Mon Sep 17 00:00:00 2001 From: "Brad P. Crochet" Date: Thu, 11 Aug 2022 14:55:24 -0400 Subject: [PATCH] Add a DebugTo convenience funtion One might want to write the debug information somewhere other than Stdout. This patch adss a DebugTo function and method, that accepts an io.Writer. It changes the original Debug implementation to call this new function with a default of os.Stdout, which maintains backward compatibility. Signed-off-by: Brad P. Crochet --- viper.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/viper.go b/viper.go index d6bbe62eae..17085ba791 100644 --- a/viper.go +++ b/viper.go @@ -2126,13 +2126,17 @@ func (v *Viper) getConfigFile() (string, error) { // Debug prints all configuration registries for debugging // purposes. func Debug() { v.Debug() } +func DebugTo(w io.Writer) { v.DebugTo(w) } -func (v *Viper) Debug() { - fmt.Printf("Aliases:\n%#v\n", v.aliases) - fmt.Printf("Override:\n%#v\n", v.override) - fmt.Printf("PFlags:\n%#v\n", v.pflags) - fmt.Printf("Env:\n%#v\n", v.env) - fmt.Printf("Key/Value Store:\n%#v\n", v.kvstore) - fmt.Printf("Config:\n%#v\n", v.config) - fmt.Printf("Defaults:\n%#v\n", v.defaults) +func (v *Viper) Debug() { v.DebugTo(os.Stdout) } + +func (v *Viper) DebugTo(w io.Writer) { + fmt.Fprintf(w, "Aliases:\n%#v\n", v.aliases) + fmt.Fprintf(w, "Override:\n%#v\n", v.override) + fmt.Fprintf(w, "PFlags:\n%#v\n", v.pflags) + fmt.Fprintf(w, "Env:\n%#v\n", v.env) + fmt.Fprintf(w, "Key/Value Store:\n%#v\n", v.kvstore) + fmt.Fprintf(w, "Config:\n%#v\n", v.config) + fmt.Fprintf(w, "Defaults:\n%#v\n", v.defaults) } +