add testing logger

This commit is contained in:
Anton Kaliaev 2017-05-03 11:06:30 +04:00
parent 66c9401c07
commit 520561e94a
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
1 changed files with 31 additions and 0 deletions

31
log/testing_logger.go Normal file
View File

@ -0,0 +1,31 @@
package log
import (
"os"
"testing"
)
var (
// reuse the same logger across all tests
_testingLogger Logger
)
// TestingLogger returns a TMLogger which writes to STDOUT if testing being run
// with the verbose (-v) flag, NopLogger otherwise.
//
// Note that the call to TestingLogger() must be made
// inside a test (not in the init func) because
// verbose flag only set at the time of testing.
func TestingLogger() Logger {
if _testingLogger != nil {
return _testingLogger
}
if testing.Verbose() {
_testingLogger = NewTMLogger(os.Stdout)
} else {
_testingLogger = NewNopLogger()
}
return _testingLogger
}