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 1/2] 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. From a9fbef94b9994ee0e703f512032211dbbeca7f7a Mon Sep 17 00:00:00 2001 From: apstndb <803393+apstndb@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:12:04 +0900 Subject: [PATCH 2/2] Fix default logger assigning --- logger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logger.go b/logger.go index 04afb9c761..1a5ae5dcdb 100644 --- a/logger.go +++ b/logger.go @@ -19,7 +19,7 @@ func init() { // 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 + Logger = log.New(os.Stderr, "", log.LstdFlags) } } }