-
Notifications
You must be signed in to change notification settings - Fork 0
/
fields.go
137 lines (110 loc) · 3.12 KB
/
fields.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
package log
import (
"fmt"
"os"
"github.com/sirupsen/logrus"
)
// Fields is used to define structured records for a log entry.
type Fields logrus.Fields
func (d Fields) print(f logFunc, skip int, v []interface{}) {
var msg interface{} = v
if len(v) == 1 {
msg = v[0]
}
d["pos"] = getFilePos(skip + 1)
if GetMode() == Production {
d["process"] = os.Args[0]
d["release"] = std.GetRelease()
}
std.print(d, msg, f)
}
func (d Fields) printf(f logFunc, skip int, format string, v []interface{}) {
d.print(f, skip+1, []interface{}{fmt.Sprintf(format, v...)})
}
type logFunc func(entry *logrus.Entry, args ...interface{})
var (
fPanic = (*logrus.Entry).Panic
fFatal = (*logrus.Entry).Fatal
fError = (*logrus.Entry).Error
fWarn = (*logrus.Entry).Warn
fInfo = (*logrus.Entry).Info
fDebug = (*logrus.Entry).Debug
)
// Panic logs at the panic level and then panic.
func (d Fields) Panic(v ...interface{}) {
d.print(fPanic, 1, v)
}
// Fatal logs at the fatal level and then os.Exit.
func (d Fields) Fatal(v ...interface{}) {
d.print(fFatal, 1, v)
}
// Error logs at the error level.
func (d Fields) Error(v ...interface{}) {
d.print(fError, 1, v)
}
// Warn logs at the warn level.
func (d Fields) Warn(v ...interface{}) {
d.print(fWarn, 1, v)
}
// Info logs at the info level.
func (d Fields) Info(v ...interface{}) {
d.print(fInfo, 1, v)
}
// Debug logs at the debug level.
func (d Fields) Debug(v ...interface{}) {
d.print(fDebug, 1, v)
}
func (d Fields) Print(v ...interface{}) {
d.print(fDebug, 1, v)
}
func (d Fields) Println(v ...interface{}) {
d.print(fDebug, 1, v)
}
// Panicf is the "format" version of Panic.
func (d Fields) Panicf(format string, v ...interface{}) {
d.printf(fPanic, 1, format, v)
}
// Fatalf is the "format" version of Fatal.
func (d Fields) Fatalf(format string, v ...interface{}) {
d.printf(fFatal, 1, format, v)
}
// Errorf is the "format" version of Error.
func (d Fields) Errorf(format string, v ...interface{}) {
d.printf(fError, 1, format, v)
}
// Warnf is the "format" version of Warn.
func (d Fields) Warnf(format string, v ...interface{}) {
d.printf(fWarn, 1, format, v)
}
// Infof is the "format" version of Info.
func (d Fields) Infof(format string, v ...interface{}) {
d.printf(fInfo, 1, format, v)
}
// Debugf is the "format" version of Debug.
func (d Fields) Debugf(format string, v ...interface{}) {
d.printf(fDebug, 1, format, v)
}
// Panic logs at the panic level and then panic.
func (d Fields) PanicWithSkip(skip int, v ...interface{}) {
d.print(fPanic, skip+1, v)
}
// Fatal logs at the fatal level and then os.Exit.
func (d Fields) FatalWithSkip(skip int, v ...interface{}) {
d.print(fFatal, skip+1, v)
}
// Error logs at the error level.
func (d Fields) ErrorWithSkip(skip int, v ...interface{}) {
d.print(fError, skip+1, v)
}
// Warn logs at the warn level.
func (d Fields) WarnWithSkip(skip int, v ...interface{}) {
d.print(fWarn, skip+1, v)
}
// Info logs at the info level.
func (d Fields) InfoWithSkip(skip int, v ...interface{}) {
d.print(fInfo, skip+1, v)
}
// Debug logs at the debug level.
func (d Fields) DebugWithSkip(skip int, v ...interface{}) {
d.print(fDebug, skip+1, v)
}