OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / tendermint / tmlibs / log / testing_logger.go
1 package log
2
3 import (
4         "os"
5         "testing"
6
7         "github.com/go-kit/kit/log/term"
8 )
9
10 var (
11         // reuse the same logger across all tests
12         _testingLogger Logger
13 )
14
15 // TestingLogger returns a TMLogger which writes to STDOUT if testing being run
16 // with the verbose (-v) flag, NopLogger otherwise.
17 //
18 // Note that the call to TestingLogger() must be made
19 // inside a test (not in the init func) because
20 // verbose flag only set at the time of testing.
21 func TestingLogger() Logger {
22         if _testingLogger != nil {
23                 return _testingLogger
24         }
25
26         if testing.Verbose() {
27                 _testingLogger = NewTMLogger(NewSyncWriter(os.Stdout))
28         } else {
29                 _testingLogger = NewNopLogger()
30         }
31
32         return _testingLogger
33 }
34
35 // TestingLoggerWithColorFn allow you to provide your own color function. See
36 // TestingLogger for documentation.
37 func TestingLoggerWithColorFn(colorFn func(keyvals ...interface{}) term.FgBgColor) Logger {
38         if _testingLogger != nil {
39                 return _testingLogger
40         }
41
42         if testing.Verbose() {
43                 _testingLogger = NewTMLoggerWithColorFn(NewSyncWriter(os.Stdout), colorFn)
44         } else {
45                 _testingLogger = NewNopLogger()
46         }
47
48         return _testingLogger
49 }