Skip to content

Commit

Permalink
chore: enable implicit default logger only in testing with -v (#2877)
Browse files Browse the repository at this point in the history
* Enable default logger only in testing

* Fix default logger assigning

---------

Co-authored-by: Manuel de la Peña <[email protected]>
  • Loading branch information
apstndb and mdelapenya authored Dec 5, 2024
1 parent 72be139 commit 512e503
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") {
Logger = log.New(os.Stderr, "", log.LstdFlags)
}
}
}

// 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 512e503

Please sign in to comment.