Skip to content
Open
Changes from 1 commit
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
11 changes: 6 additions & 5 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ type Logger interface {
Printf(format string, v ...any)
}

// defaultLogger is the default Logger instance.
var defaultLogger Logger = &noopLogger{}
// defaultLogger would print available information to stderr
var defaultLogger Logger = log.New(os.Stderr, "", log.LstdFlags)

func init() {
// Enable default logger in the testing with a verbose flag.
if testing.Testing() {
// Parse manually because testing.Verbose() panics unless flag.Parse() has done.
// Disable logging if explicitly disabled via -test.v=false
for _, arg := range os.Args {
if strings.EqualFold(arg, "-test.v=true") || strings.EqualFold(arg, "-v") {
defaultLogger = log.New(os.Stderr, "", log.LstdFlags)
if strings.EqualFold(arg, "-test.v=false") {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Create a public constructor for the noopLogger, or remove it and use log.New(io.Discard, "", 0)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@strowk what are your thoughts on this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easy enough - fba533f

defaultLogger = &noopLogger{}
break
}
}
}
Expand Down
Loading