forked from jcelliott/lumber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multilog.go
134 lines (109 loc) · 2.51 KB
/
multilog.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package lumber
import (
"fmt"
"time"
)
type MultiLogger struct {
loggers []Logger
}
func NewMultiLogger() (l *MultiLogger) {
return &MultiLogger{}
}
func (p *MultiLogger) AddLoggers(newLogs ...Logger) {
for _, l := range newLogs {
p.loggers = append(p.loggers, l)
}
}
func (p *MultiLogger) ClearLoggers() {
p.loggers = make([]Logger, 0)
}
// All of these implement the Logger interface and distribute calls to it over
// all of the member Logger objects.
func (p *MultiLogger) Fatal(s string, v ...interface{}) {
for _, logger := range p.loggers {
logger.Fatal(s, v...)
}
}
func (p *MultiLogger) Error(s string, v ...interface{}) {
for _, logger := range p.loggers {
logger.Error(s, v...)
}
}
func (p *MultiLogger) Warn(s string, v ...interface{}) {
for _, logger := range p.loggers {
logger.Warn(s, v...)
}
}
func (p *MultiLogger) Info(s string, v ...interface{}) {
for _, logger := range p.loggers {
logger.Info(s, v...)
}
}
func (p *MultiLogger) Debug(s string, v ...interface{}) {
for _, logger := range p.loggers {
logger.Debug(s, v...)
}
}
func (p *MultiLogger) Trace(s string, v ...interface{}) {
for _, logger := range p.loggers {
logger.Trace(s, v...)
}
}
func (p *MultiLogger) Level(i int) {
for _, logger := range p.loggers {
logger.Level(i)
}
}
func (p *MultiLogger) Prefix(s string) {
for _, logger := range p.loggers {
logger.Prefix(s)
}
}
func (p *MultiLogger) TimeFormat(s string) {
for _, logger := range p.loggers {
logger.TimeFormat(s)
}
}
func (p *MultiLogger) Close() {
for _, logger := range p.loggers {
logger.Close()
}
}
func (p *MultiLogger) output(m *Message) {
for _, logger := range p.loggers {
logger.output(m)
}
}
func (p *MultiLogger) Print(lvl int, v ...interface{}) {
p.output(&Message{lvl, fmt.Sprint(v...), time.Now()})
}
func (p *MultiLogger) Printf(lvl int, format string, v ...interface{}) {
p.output(&Message{lvl, fmt.Sprintf(format, v...), time.Now()})
}
func (p *MultiLogger) GetLevel() int {
level := FATAL
for _, logger := range p.loggers {
if logger.GetLevel() <= level {
level = logger.GetLevel()
}
}
return level
}
func (p *MultiLogger) IsFatal() bool {
return p.GetLevel() <= FATAL
}
func (p *MultiLogger) IsError() bool {
return p.GetLevel() <= ERROR
}
func (p *MultiLogger) IsWarn() bool {
return p.GetLevel() <= WARN
}
func (p *MultiLogger) IsInfo() bool {
return p.GetLevel() <= INFO
}
func (p *MultiLogger) IsDebug() bool {
return p.GetLevel() <= DEBUG
}
func (p *MultiLogger) IsTrace() bool {
return p.GetLevel() <= TRACE
}