Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actually write to stdout for Debug() no params #25

Merged
merged 1 commit into from
Jun 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading