From 520561e94a11040272fc64e5f338eacdc336ea3d Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 3 May 2017 11:06:30 +0400 Subject: [PATCH] add testing logger --- log/testing_logger.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 log/testing_logger.go diff --git a/log/testing_logger.go b/log/testing_logger.go new file mode 100644 index 000000000..7ab83e414 --- /dev/null +++ b/log/testing_logger.go @@ -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 +}