forked from nitishm/logger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logrus.go
176 lines (168 loc) · 4.13 KB
/
logrus.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package logger
import log "github.com/sirupsen/logrus"
// Logrus interface is an alias for the upstream logrus interface
// This makes logrus methods concurrency safe.
type Logrus log.Ext1FieldLogger
// Add a single field to the Entry
func (l *logger) WithField(key string, value interface{}) *log.Entry {
l.mu.Lock()
defer l.mu.Unlock()
return l.Entry.WithField(key, value)
}
// Add a map of fields to the Entry.
func (l *logger) WithFields(fields log.Fields) *log.Entry {
l.mu.Lock()
defer l.mu.Unlock()
return l.Entry.WithFields(fields)
}
// Add an error as single field (using the key defined in ErrorKey) to the Entry.
func (l *logger) WithError(err error) *log.Entry {
l.mu.Lock()
defer l.mu.Unlock()
return l.Entry.WithError(err)
}
func (l *logger) Debugf(format string, args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Debugf(format, args...)
}
func (l *logger) Infof(format string, args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Infof(format, args...)
}
func (l *logger) Printf(format string, args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Printf(format, args...)
}
func (l *logger) Warnf(format string, args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Warnf(format, args...)
}
func (l *logger) Warningf(format string, args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Warningf(format, args...)
}
func (l *logger) Errorf(format string, args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Errorf(format, args...)
}
func (l *logger) Fatalf(format string, args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Fatalf(format, args...)
}
func (l *logger) Panicf(format string, args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Panicf(format, args...)
}
func (l *logger) Debug(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Debug(args...)
}
func (l *logger) Info(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Info(args...)
}
func (l *logger) Print(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Print(args...)
}
func (l *logger) Warn(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Warn(args...)
}
func (l *logger) Warning(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Warning(args...)
}
func (l *logger) Error(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Error(args...)
}
func (l *logger) Fatal(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Fatal(args...)
}
func (l *logger) Panic(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Panic(args...)
}
func (l *logger) Debugln(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Debugln(args...)
}
func (l *logger) Infoln(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Infoln(args...)
}
func (l *logger) Println(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Println(args...)
}
func (l *logger) Warnln(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Warnln(args...)
}
func (l *logger) Warningln(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Warningln(args...)
}
func (l *logger) Errorln(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Errorln(args...)
}
func (l *logger) Fatalln(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Fatalln(args...)
}
func (l *logger) Panicln(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Panicln(args...)
}
func (l *logger) Tracef(format string, args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Tracef(format, args...)
}
func (l *logger) Trace(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Trace(args...)
}
func (l *logger) Traceln(args ...interface{}) {
l.mu.RLock()
defer l.mu.RUnlock()
l.Entry.Traceln(args...)
}
// Clone creates a shallow copy of the logger
// and returns a new instance.
// NOTE: That the logrus Entry ptr is not passed
// along from the original Logger.
func (l *logger) Clone() Logger {
var clone *logger = New()
clone.SetDefaults(l.Defaults())
clone.AddFields(l.Fields())
return clone
}