Skip to content

Commit

Permalink
Merge pull request #25 from jaypipes/debug
Browse files Browse the repository at this point in the history
actually write to stdout for Debug() no params
  • Loading branch information
jaypipes authored Jun 16, 2024
2 parents e330962 + 98ba146 commit d8de82a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ type ContextModifier func(context.Context) context.Context
// zero or more `io.Writer` objects to the function.
//
// If no `io.Writer` objects are supplied, gdt will output debug messages using
// the `testing.T.Log[f]()` function. This means that you will only get these
// debug messages if you call the `go test` tool with the `-v` option (either
// as `go test -v` or with `go test -v=test2json`.
// the `fmt.Printf` function. The `fmt.Printf` function is *unbuffered* however
// unless you call `go test` with the `-v` argument, `go test` swallows output
// to stdout and does not display it unless a test fails.
//
// This means that you will only get these debug messages if you call the `go
// test` tool with the `-v` option (either as `go test -v` or with `go test
// -v=test2json`.
//
// ```go
//
Expand Down Expand Up @@ -76,9 +80,8 @@ type ContextModifier func(context.Context) context.Context
func WithDebug(writers ...io.Writer) ContextModifier {
return func(ctx context.Context) context.Context {
if len(writers) == 0 {
// This simply triggers a call to t.Logf() when WithDebug() is
// called with no parameters...
writers = []io.Writer{io.Discard}
// Write to stdout when WithDebug() is called with no parameters
writers = []io.Writer{os.Stdout}
}
return context.WithValue(ctx, debugKey, writers)
}
Expand Down

0 comments on commit d8de82a

Please sign in to comment.