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 <brad@redhat.com>
This commit is contained in:
Brad P. Crochet 2022-08-11 14:55:24 -04:00 committed by Márk Sági-Kazár
parent 202060b3a2
commit 312417a0c5

View file

@ -2136,13 +2136,16 @@ func (v *Viper) getConfigFile() (string, error) {
// Debug prints all configuration registries for debugging // Debug prints all configuration registries for debugging
// purposes. // purposes.
func Debug() { v.Debug() } func Debug() { v.Debug() }
func DebugTo(w io.Writer) { v.DebugTo(w) }
func (v *Viper) Debug() { func (v *Viper) Debug() { v.DebugTo(os.Stdout) }
fmt.Printf("Aliases:\n%#v\n", v.aliases)
fmt.Printf("Override:\n%#v\n", v.override) func (v *Viper) DebugTo(w io.Writer) {
fmt.Printf("PFlags:\n%#v\n", v.pflags) fmt.Fprintf(w, "Aliases:\n%#v\n", v.aliases)
fmt.Printf("Env:\n%#v\n", v.env) fmt.Fprintf(w, "Override:\n%#v\n", v.override)
fmt.Printf("Key/Value Store:\n%#v\n", v.kvstore) fmt.Fprintf(w, "PFlags:\n%#v\n", v.pflags)
fmt.Printf("Config:\n%#v\n", v.config) fmt.Fprintf(w, "Env:\n%#v\n", v.env)
fmt.Printf("Defaults:\n%#v\n", v.defaults) 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)
} }