-
Notifications
You must be signed in to change notification settings - Fork 13
/
std.go
104 lines (91 loc) · 2.79 KB
/
std.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
package xlog
import "fmt"
var std = New(Config{
Output: NewConsoleOutput(),
})
// SetLogger changes the global logger instance
func SetLogger(logger Logger) {
std = logger
}
// Debug calls the Debug() method on the default logger
func Debug(v ...interface{}) {
f := extractFields(&v)
std.OutputF(LevelDebug, 2, fmt.Sprint(v...), f)
}
// Debugf calls the Debugf() method on the default logger
func Debugf(format string, v ...interface{}) {
f := extractFields(&v)
std.OutputF(LevelDebug, 2, fmt.Sprintf(format, v...), f)
}
// Info calls the Info() method on the default logger
func Info(v ...interface{}) {
f := extractFields(&v)
std.OutputF(LevelInfo, 2, fmt.Sprint(v...), f)
}
// Infof calls the Infof() method on the default logger
func Infof(format string, v ...interface{}) {
f := extractFields(&v)
std.OutputF(LevelInfo, 2, fmt.Sprintf(format, v...), f)
}
// Warn calls the Warn() method on the default logger
func Warn(v ...interface{}) {
f := extractFields(&v)
std.OutputF(LevelWarn, 2, fmt.Sprint(v...), f)
}
// Warnf calls the Warnf() method on the default logger
func Warnf(format string, v ...interface{}) {
f := extractFields(&v)
std.OutputF(LevelWarn, 2, fmt.Sprintf(format, v...), f)
}
// Error calls the Error() method on the default logger
func Error(v ...interface{}) {
f := extractFields(&v)
std.OutputF(LevelError, 2, fmt.Sprint(v...), f)
}
// Errorf calls the Errorf() method on the default logger
//
// Go vet users: you may append %v at the end of you format when using xlog.F{} as a last
// argument to workaround go vet false alarm.
func Errorf(format string, v ...interface{}) {
f := extractFields(&v)
if f != nil {
// Let user add a %v at the end of the message when fields are passed to satisfy go vet
l := len(format)
if l > 2 && format[l-2] == '%' && format[l-1] == 'v' {
format = format[0 : l-2]
}
}
std.OutputF(LevelError, 2, fmt.Sprintf(format, v...), f)
}
// Fatal calls the Fatal() method on the default logger
func Fatal(v ...interface{}) {
f := extractFields(&v)
std.OutputF(LevelFatal, 2, fmt.Sprint(v...), f)
if l, ok := std.(*logger); ok {
if o, ok := l.output.(*OutputChannel); ok {
o.Close()
}
}
exit1()
}
// Fatalf calls the Fatalf() method on the default logger
//
// Go vet users: you may append %v at the end of you format when using xlog.F{} as a last
// argument to workaround go vet false alarm.
func Fatalf(format string, v ...interface{}) {
f := extractFields(&v)
if f != nil {
// Let user add a %v at the end of the message when fields are passed to satisfy go vet
l := len(format)
if l > 2 && format[l-2] == '%' && format[l-1] == 'v' {
format = format[0 : l-2]
}
}
std.OutputF(LevelFatal, 2, fmt.Sprintf(format, v...), f)
if l, ok := std.(*logger); ok {
if o, ok := l.output.(*OutputChannel); ok {
o.Close()
}
}
exit1()
}