-
Notifications
You must be signed in to change notification settings - Fork 641
/
test_log.go
93 lines (54 loc) · 2.19 KB
/
test_log.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package logging
import (
"errors"
"sync"
)
var errNoLoggerWrite = errors.New("NoLogger can't write")
type NoLog struct{}
func (NoLog) Write([]byte) (int, error) { return 0, errNoLoggerWrite }
func (NoLog) Fatal(format string, args ...interface{}) {}
func (NoLog) Error(format string, args ...interface{}) {}
func (NoLog) Warn(format string, args ...interface{}) {}
func (NoLog) Info(format string, args ...interface{}) {}
func (NoLog) Trace(format string, args ...interface{}) {}
func (NoLog) Debug(format string, args ...interface{}) {}
func (NoLog) Verbo(format string, args ...interface{}) {}
func (NoLog) AssertNoError(error) {}
func (NoLog) AssertTrue(b bool, format string, args ...interface{}) {}
func (NoLog) AssertDeferredTrue(f func() bool, format string, args ...interface{}) {}
func (NoLog) AssertDeferredNoError(f func() error) {}
func (NoLog) StopOnPanic() {}
func (NoLog) RecoverAndPanic(f func()) { f() }
func (NoLog) RecoverAndExit(f, exit func()) { defer exit(); f() }
func (NoLog) Stop() {}
func (NoLog) SetLogLevel(Level) {}
func (NoLog) SetDisplayLevel(Level) {}
// GetLogLevel ...
func (NoLog) GetLogLevel() Level { return Off }
// GetDisplayLevel ...
func (NoLog) GetDisplayLevel() Level { return Off }
// SetPrefix ...
func (NoLog) SetPrefix(string) {}
func (NoLog) SetLoggingEnabled(bool) {}
func (NoLog) SetDisplayingEnabled(bool) {}
func (NoLog) SetContextualDisplayingEnabled(bool) {}
// NoIOWriter is a mock Writer that does not write to any underlying source
type NoIOWriter struct{}
func (nw *NoIOWriter) Initialize(Config) (int, error) { return 0, nil }
func (nw *NoIOWriter) Flush() error { return nil }
func (nw *NoIOWriter) Write(p []byte) (int, error) { return len(p), nil }
func (nw *NoIOWriter) WriteString(s string) (int, error) { return len(s), nil }
func (nw *NoIOWriter) Close() error { return nil }
func (nw *NoIOWriter) Rotate() error { return nil }
func NewTestLog(config Config) (*Log, error) {
l := &Log{
config: config,
writer: &NoIOWriter{},
}
l.needsFlush = sync.NewCond(&l.flushLock)
l.wg.Add(1)
go l.RecoverAndPanic(l.run)
return l, nil
}