Skip to content

Commit d8de82a

Browse files
authored
Merge pull request #25 from jaypipes/debug
actually write to stdout for Debug() no params
2 parents e330962 + 98ba146 commit d8de82a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

context/context.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ type ContextModifier func(context.Context) context.Context
3030
// zero or more `io.Writer` objects to the function.
3131
//
3232
// If no `io.Writer` objects are supplied, gdt will output debug messages using
33-
// the `testing.T.Log[f]()` function. This means that you will only get these
34-
// debug messages if you call the `go test` tool with the `-v` option (either
35-
// as `go test -v` or with `go test -v=test2json`.
33+
// the `fmt.Printf` function. The `fmt.Printf` function is *unbuffered* however
34+
// unless you call `go test` with the `-v` argument, `go test` swallows output
35+
// to stdout and does not display it unless a test fails.
36+
//
37+
// This means that you will only get these debug messages if you call the `go
38+
// test` tool with the `-v` option (either as `go test -v` or with `go test
39+
// -v=test2json`.
3640
//
3741
// ```go
3842
//
@@ -76,9 +80,8 @@ type ContextModifier func(context.Context) context.Context
7680
func WithDebug(writers ...io.Writer) ContextModifier {
7781
return func(ctx context.Context) context.Context {
7882
if len(writers) == 0 {
79-
// This simply triggers a call to t.Logf() when WithDebug() is
80-
// called with no parameters...
81-
writers = []io.Writer{io.Discard}
83+
// Write to stdout when WithDebug() is called with no parameters
84+
writers = []io.Writer{os.Stdout}
8285
}
8386
return context.WithValue(ctx, debugKey, writers)
8487
}

0 commit comments

Comments
 (0)