Skip to content

Commit

Permalink
Enable default logger only in testing
Browse files Browse the repository at this point in the history
  • Loading branch information
apstndb committed Nov 6, 2024
1 parent ac572ca commit bd0088b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ import (
)

// Logger is the default log instance
var Logger Logging = log.New(os.Stderr, "", log.LstdFlags)
var Logger Logging = &noopLogger{}

func init() {
for _, arg := range os.Args {
if strings.EqualFold(arg, "-test.v=true") || strings.EqualFold(arg, "-v") {
return
// Enable default logger in the testing with a verbose flag.
if testing.Testing() {
// Parse manually because testing.Verbose() panics unless flag.Parse() has done.
for _, arg := range os.Args {
if strings.EqualFold(arg, "-test.v=true") || strings.EqualFold(arg, "-v") {
return
}
}
}

// If we are not running in verbose mode, we configure a noop logger by default.
Logger = &noopLogger{}
}

// Validate our types implement the required interfaces.
Expand Down

0 comments on commit bd0088b

Please sign in to comment.