You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
628 B

  1. package log
  2. import (
  3. "os"
  4. "testing"
  5. )
  6. var (
  7. // reuse the same logger across all tests
  8. _testingLogger Logger
  9. )
  10. // TestingLogger returns a TMLogger which writes to STDOUT if testing being run
  11. // with the verbose (-v) flag, NopLogger otherwise.
  12. //
  13. // Note that the call to TestingLogger() must be made
  14. // inside a test (not in the init func) because
  15. // verbose flag only set at the time of testing.
  16. func TestingLogger() Logger {
  17. if _testingLogger != nil {
  18. return _testingLogger
  19. }
  20. if testing.Verbose() {
  21. _testingLogger = NewTMLogger(os.Stdout)
  22. } else {
  23. _testingLogger = NewNopLogger()
  24. }
  25. return _testingLogger
  26. }