|
@ -1,6 +1,7 @@ |
|
|
package log |
|
|
package log |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
|
|
|
"io" |
|
|
"os" |
|
|
"os" |
|
|
"testing" |
|
|
"testing" |
|
|
|
|
|
|
|
@ -19,12 +20,22 @@ var ( |
|
|
// inside a test (not in the init func) because
|
|
|
// inside a test (not in the init func) because
|
|
|
// verbose flag only set at the time of testing.
|
|
|
// verbose flag only set at the time of testing.
|
|
|
func TestingLogger() Logger { |
|
|
func TestingLogger() Logger { |
|
|
|
|
|
return TestingLoggerWithOutput(os.Stdout) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TestingLoggerWOutput returns a TMLogger which writes to (w io.Writer) if testing being run
|
|
|
|
|
|
// with the verbose (-v) flag, NopLogger otherwise.
|
|
|
|
|
|
//
|
|
|
|
|
|
// Note that the call to TestingLoggerWithOutput(w io.Writer) must be made
|
|
|
|
|
|
// inside a test (not in the init func) because
|
|
|
|
|
|
// verbose flag only set at the time of testing.
|
|
|
|
|
|
func TestingLoggerWithOutput(w io.Writer) Logger { |
|
|
if _testingLogger != nil { |
|
|
if _testingLogger != nil { |
|
|
return _testingLogger |
|
|
return _testingLogger |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if testing.Verbose() { |
|
|
if testing.Verbose() { |
|
|
_testingLogger = NewTMLogger(NewSyncWriter(os.Stdout)) |
|
|
|
|
|
|
|
|
_testingLogger = NewTMLogger(NewSyncWriter(w)) |
|
|
} else { |
|
|
} else { |
|
|
_testingLogger = NewNopLogger() |
|
|
_testingLogger = NewNopLogger() |
|
|
} |
|
|
} |
|
|