Skip to content

Commit 4906505

Browse files
committed
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>
1 parent 5247643 commit 4906505

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

viper.go

+12-8
Original file line numberDiff line numberDiff line change
@@ -2126,13 +2126,17 @@ func (v *Viper) getConfigFile() (string, error) {
21262126
// Debug prints all configuration registries for debugging
21272127
// purposes.
21282128
func Debug() { v.Debug() }
2129+
func DebugTo(w io.Writer) { v.DebugTo(w) }
21292130

2130-
func (v *Viper) Debug() {
2131-
fmt.Printf("Aliases:\n%#v\n", v.aliases)
2132-
fmt.Printf("Override:\n%#v\n", v.override)
2133-
fmt.Printf("PFlags:\n%#v\n", v.pflags)
2134-
fmt.Printf("Env:\n%#v\n", v.env)
2135-
fmt.Printf("Key/Value Store:\n%#v\n", v.kvstore)
2136-
fmt.Printf("Config:\n%#v\n", v.config)
2137-
fmt.Printf("Defaults:\n%#v\n", v.defaults)
2131+
func (v *Viper) Debug() { v.DebugTo(os.Stdout) }
2132+
2133+
func (v *Viper) DebugTo(w io.Writer) {
2134+
fmt.Fprintf(w, "Aliases:\n%#v\n", v.aliases)
2135+
fmt.Fprintf(w, "Override:\n%#v\n", v.override)
2136+
fmt.Fprintf(w, "PFlags:\n%#v\n", v.pflags)
2137+
fmt.Fprintf(w, "Env:\n%#v\n", v.env)
2138+
fmt.Fprintf(w, "Key/Value Store:\n%#v\n", v.kvstore)
2139+
fmt.Fprintf(w, "Config:\n%#v\n", v.config)
2140+
fmt.Fprintf(w, "Defaults:\n%#v\n", v.defaults)
21382141
}
2142+

0 commit comments

Comments
 (0)