github.com/number571/tendermint@v0.34.11-gost/libs/log/testing.go (about) 1 package log 2 3 import ( 4 "io" 5 "os" 6 "sync" 7 "testing" 8 ) 9 10 var ( 11 // reuse the same logger across all tests 12 testingLoggerMtx = sync.Mutex{} 13 testingLogger Logger 14 ) 15 16 // TestingLogger returns a Logger which writes to STDOUT if test(s) are being 17 // run with the verbose (-v) flag, NopLogger otherwise. 18 // 19 // NOTE: 20 // - A call to NewTestingLogger() must be made inside a test (not in the init func) 21 // because verbose flag only set at the time of testing. 22 func TestingLogger() Logger { 23 return TestingLoggerWithOutput(os.Stdout) 24 } 25 26 func TestingLoggerWithOutput(w io.Writer) Logger { 27 testingLoggerMtx.Lock() 28 defer testingLoggerMtx.Unlock() 29 30 if testingLogger != nil { 31 return testingLogger 32 } 33 34 if testing.Verbose() { 35 testingLogger = MustNewDefaultLogger(LogFormatText, LogLevelDebug, true) 36 } else { 37 testingLogger = NewNopLogger() 38 } 39 40 return testingLogger 41 }