From bd0088b0991507f7f46461724c8db31d538a2eee Mon Sep 17 00:00:00 2001 From: apstndb <803393+apstndb@users.noreply.github.com> Date: Wed, 6 Nov 2024 18:51:57 +0900 Subject: [PATCH] Enable default logger only in testing --- logger.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/logger.go b/logger.go index fca5da5398..04afb9c761 100644 --- a/logger.go +++ b/logger.go @@ -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.