Skip to content

Commit 312417a

Browse files
bcrochetsagikazarmark
authored andcommitted
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 202060b commit 312417a

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

viper.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -2135,14 +2135,17 @@ func (v *Viper) getConfigFile() (string, error) {
21352135

21362136
// Debug prints all configuration registries for debugging
21372137
// purposes.
2138-
func Debug() { v.Debug() }
2139-
2140-
func (v *Viper) Debug() {
2141-
fmt.Printf("Aliases:\n%#v\n", v.aliases)
2142-
fmt.Printf("Override:\n%#v\n", v.override)
2143-
fmt.Printf("PFlags:\n%#v\n", v.pflags)
2144-
fmt.Printf("Env:\n%#v\n", v.env)
2145-
fmt.Printf("Key/Value Store:\n%#v\n", v.kvstore)
2146-
fmt.Printf("Config:\n%#v\n", v.config)
2147-
fmt.Printf("Defaults:\n%#v\n", v.defaults)
2138+
func Debug() { v.Debug() }
2139+
func DebugTo(w io.Writer) { v.DebugTo(w) }
2140+
2141+
func (v *Viper) Debug() { v.DebugTo(os.Stdout) }
2142+
2143+
func (v *Viper) DebugTo(w io.Writer) {
2144+
fmt.Fprintf(w, "Aliases:\n%#v\n", v.aliases)
2145+
fmt.Fprintf(w, "Override:\n%#v\n", v.override)
2146+
fmt.Fprintf(w, "PFlags:\n%#v\n", v.pflags)
2147+
fmt.Fprintf(w, "Env:\n%#v\n", v.env)
2148+
fmt.Fprintf(w, "Key/Value Store:\n%#v\n", v.kvstore)
2149+
fmt.Fprintf(w, "Config:\n%#v\n", v.config)
2150+
fmt.Fprintf(w, "Defaults:\n%#v\n", v.defaults)
21482151
}

0 commit comments

Comments
 (0)