This repository was archived by the owner on Mar 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathlg.go
157 lines (127 loc) · 3.53 KB
/
lg.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
package lg
import (
"fmt"
"runtime"
"github.com/sirupsen/logrus"
)
var (
DefaultLogger *logrus.Logger = logrus.New()
AlertFn func(level logrus.Level, msg string)
)
func WithField(key string, value interface{}) *logrus.Entry {
return DefaultLogger.WithField(key, value)
}
func WithFields(fields logrus.Fields) *logrus.Entry {
return DefaultLogger.WithFields(fields)
}
func WithError(err error) *logrus.Entry {
return DefaultLogger.WithError(err)
}
func Debugf(format string, args ...interface{}) {
DefaultLogger.Debugf(format, args...)
}
func Infof(format string, args ...interface{}) {
DefaultLogger.Infof(format, args...)
}
func Printf(format string, args ...interface{}) {
DefaultLogger.Printf(format, args...)
}
func Warnf(format string, args ...interface{}) {
DefaultLogger.Warnf(format, args...)
}
func Errorf(format string, args ...interface{}) {
DefaultLogger.Errorf(format, args...)
}
func Alertf(format string, args ...interface{}) {
if AlertFn != nil {
_, file, line, _ := runtime.Caller(1)
AlertFn(logrus.ErrorLevel, fmt.Sprintf("%s:%d ", file, line)+fmt.Sprintf(format, args...))
}
Errorf(format, args...)
}
func Fatalf(format string, args ...interface{}) {
if AlertFn != nil {
_, file, line, _ := runtime.Caller(1)
AlertFn(logrus.FatalLevel, fmt.Sprintf("%s:%d ", file, line)+fmt.Sprintf(format, args...))
}
DefaultLogger.Fatalf(format, args...)
}
func Panicf(format string, args ...interface{}) {
if AlertFn != nil {
_, file, line, _ := runtime.Caller(1)
AlertFn(logrus.PanicLevel, fmt.Sprintf("%s:%d ", file, line)+fmt.Sprintf(format, args...))
}
DefaultLogger.Panicf(format, args...)
}
func Debug(args ...interface{}) {
DefaultLogger.Debug(args...)
}
func Info(args ...interface{}) {
DefaultLogger.Info(args...)
}
func Print(args ...interface{}) {
DefaultLogger.Print(args...)
}
func Warn(args ...interface{}) {
DefaultLogger.Warn(args...)
}
func Error(args ...interface{}) {
DefaultLogger.Error(args...)
}
func Alert(args ...interface{}) {
if AlertFn != nil {
_, file, line, _ := runtime.Caller(1)
AlertFn(logrus.ErrorLevel, fmt.Sprintf("%s:%d ", file, line)+fmt.Sprint(args...))
}
Error(args...)
}
func Fatal(args ...interface{}) {
if AlertFn != nil {
_, file, line, _ := runtime.Caller(1)
AlertFn(logrus.FatalLevel, fmt.Sprintf("%s:%d ", file, line)+fmt.Sprint(args...))
}
DefaultLogger.Fatal(args...)
}
func Panic(args ...interface{}) {
if AlertFn != nil {
_, file, line, _ := runtime.Caller(1)
AlertFn(logrus.PanicLevel, fmt.Sprintf("%s:%d ", file, line)+fmt.Sprint(args...))
}
DefaultLogger.Panic(args...)
}
func Debugln(args ...interface{}) {
DefaultLogger.Debugln(args...)
}
func Infoln(args ...interface{}) {
DefaultLogger.Infoln(args...)
}
func Println(args ...interface{}) {
DefaultLogger.Println(args...)
}
func Warnln(args ...interface{}) {
DefaultLogger.Warnln(args...)
}
func Errorln(args ...interface{}) {
DefaultLogger.Errorln(args...)
}
func Alertln(args ...interface{}) {
if AlertFn != nil {
_, file, line, _ := runtime.Caller(1)
AlertFn(logrus.ErrorLevel, fmt.Sprintf("%s:%d ", file, line)+fmt.Sprintln(args...))
}
Errorln(args...)
}
func Fatalln(args ...interface{}) {
if AlertFn != nil {
_, file, line, _ := runtime.Caller(1)
AlertFn(logrus.FatalLevel, fmt.Sprintf("%s:%d ", file, line)+fmt.Sprintln(args...))
}
DefaultLogger.Fatalln(args...)
}
func Panicln(args ...interface{}) {
if AlertFn != nil {
_, file, line, _ := runtime.Caller(1)
AlertFn(logrus.PanicLevel, fmt.Sprintf("%s:%d ", file, line)+fmt.Sprintln(args...))
}
DefaultLogger.Panicln(args...)
}