This repository has been archived by the owner on Jan 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
entry.go
195 lines (163 loc) · 5.02 KB
/
entry.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package logger
import (
"fmt"
"os"
"time"
"github.com/sirupsen/logrus"
)
const (
errorLevelKey = "errorLevel"
)
type Entry struct {
logrus.Entry
}
func (entry *Entry) WithError(err error) *Entry {
return &Entry{*entry.Entry.WithError(err)}
}
func (entry *Entry) WithField(key string, value interface{}) *Entry {
return &Entry{*entry.Entry.WithField(key, value)}
}
func (entry *Entry) WithFields(fields logrus.Fields) *Entry {
return &Entry{*entry.Entry.WithFields(fields)}
}
// Entry Print family functions:
// Debug logs the args at the Debug level.
func (entry *Entry) Debug(args ...interface{}) {
if logger.Level >= logrus.DebugLevel {
entry.Entry.Debug(args...)
}
}
// Info logs the args at the Info level.
func (entry *Entry) Info(args ...interface{}) {
if logger.Level >= logrus.InfoLevel {
entry.Entry.Info(args...)
}
}
// Print logs the args at the Info level.
func (entry *Entry) Print(args ...interface{}) {
entry.Info(args...)
}
// Warn logs the args at the Warn level.
func (entry *Entry) Warn(args ...interface{}) {
if logger.Level >= logrus.WarnLevel {
entry.Entry.Warn(args...)
}
}
// Warning logs the args at the Warn level.
func (entry *Entry) Warning(args ...interface{}) {
if logger.Level >= logrus.WarnLevel {
entry.Entry.Warn(args...)
}
}
// Error logs the args at the Error level.
func (entry *Entry) Error(args ...interface{}) {
if logger.Level >= logrus.ErrorLevel {
entry.WithField(errorLevelKey, "error").Entry.Error(args...)
}
}
// Fatal logs the args at the Error level and exits.
func (entry *Entry) Fatal(args ...interface{}) {
entry.WithField(errorLevelKey, "fatal").Entry.Error(args...)
safeRollbarWait(time.Second)
os.Exit(1)
}
// Panic logs the args at the Error level and panics.
func (entry *Entry) Panic(args ...interface{}) {
entry.WithField(errorLevelKey, "panic").Entry.Error(args...)
safeRollbarWait(time.Second)
panic(fmt.Sprint(args...))
}
// Entry Printf family functions:
// Debugf logs the formatted string at Debug level.
func (entry *Entry) Debugf(format string, args ...interface{}) {
if logger.Level >= logrus.DebugLevel {
entry.Entry.Debugf(format, args...)
}
}
// Infof logs the formatted string at Info level.
func (entry *Entry) Infof(format string, args ...interface{}) {
if logger.Level >= logrus.InfoLevel {
entry.Entry.Infof(format, args...)
}
}
// Printf logs the formatted string at Info level.
func (entry *Entry) Printf(format string, args ...interface{}) {
entry.Infof(format, args...)
}
// Warnf logs the formatted string at Warn level.
func (entry *Entry) Warnf(format string, args ...interface{}) {
if logger.Level >= logrus.WarnLevel {
entry.Entry.Warnf(format, args...)
}
}
// Warningf logs the formatted string at Warn level.
func (entry *Entry) Warningf(format string, args ...interface{}) {
if logger.Level >= logrus.WarnLevel {
entry.Entry.Warnf(format, args...)
}
}
// Errorf logs the formatted string at Error level.
func (entry *Entry) Errorf(format string, args ...interface{}) {
if logger.Level >= logrus.ErrorLevel {
entry.WithField(errorLevelKey, "error").Entry.Errorf(format, args...)
}
}
// Fatalf logs the formatted string at Error level and exits.
func (entry *Entry) Fatalf(format string, args ...interface{}) {
entry.WithField(errorLevelKey, "fatal").Entry.Errorf(format, args...)
safeRollbarWait(time.Second)
os.Exit(1)
}
// Panicf logs the formatted string at Error level and panics.
func (entry *Entry) Panicf(format string, args ...interface{}) {
entry.WithField(errorLevelKey, "panic").Entry.Errorf(format, args...)
safeRollbarWait(time.Second)
panic(fmt.Sprint(args...))
}
// Entry Println family functions:
// Debugln logs the args at the Debug level.
func (entry *Entry) Debugln(args ...interface{}) {
if logger.Level >= logrus.DebugLevel {
entry.Entry.Debugln(args...)
}
}
// Infoln logs the args at the Info level.
func (entry *Entry) Infoln(args ...interface{}) {
if logger.Level >= logrus.InfoLevel {
entry.Entry.Infoln(args...)
}
}
// Println logs the args at the Info level.
func (entry *Entry) Println(args ...interface{}) {
entry.Infoln(args...)
}
// Warnln logs the args at the Warn level.
func (entry *Entry) Warnln(args ...interface{}) {
if logger.Level >= logrus.WarnLevel {
entry.Entry.Warnln(args...)
}
}
// Warningln logs the args at the Warn level.
func (entry *Entry) Warningln(args ...interface{}) {
if logger.Level >= logrus.WarnLevel {
entry.Entry.Warnln(args...)
}
}
// Errorln logs the args at the Error level.
func (entry *Entry) Errorln(args ...interface{}) {
if logger.Level >= logrus.ErrorLevel {
entry.WithField(errorLevelKey, "error").Entry.Errorln(args...)
}
}
// Fatalln logs the args at the Error level and exits.
func (entry *Entry) Fatalln(args ...interface{}) {
entry.WithField(errorLevelKey, "fatal").Entry.Errorln(args...)
safeRollbarWait(time.Second)
os.Exit(1)
}
// Panicln logs the args at the Error level and panics.
func (entry *Entry) Panicln(args ...interface{}) {
entry.WithField(errorLevelKey, "panic").Entry.Errorln(args...)
safeRollbarWait(time.Second)
panic(fmt.Sprint(args...))
}