forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloggers.go
177 lines (138 loc) · 3.57 KB
/
loggers.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
package log
import (
"fmt"
"log"
)
// Info takes a pointer subLogger struct and string sends to newLogEvent
func Info(sl *subLogger, data string) {
if sl == nil || !enabled() {
return
}
if !sl.Info {
return
}
displayError(logger.newLogEvent(data, logger.InfoHeader, sl.name, sl.output))
}
// Infoln takes a pointer subLogger struct and interface sends to newLogEvent
func Infoln(sl *subLogger, v ...interface{}) {
if sl == nil || !enabled() {
return
}
if !sl.Info {
return
}
displayError(logger.newLogEvent(fmt.Sprintln(v...), logger.InfoHeader, sl.name, sl.output))
}
// Infof takes a pointer subLogger struct, string & interface formats and sends to Info()
func Infof(sl *subLogger, data string, v ...interface{}) {
if sl == nil || !enabled() {
return
}
if !sl.Info {
return
}
Info(sl, fmt.Sprintf(data, v...))
}
// Debug takes a pointer subLogger struct and string sends to multiwriter
func Debug(sl *subLogger, data string) {
if sl == nil || !enabled() {
return
}
if !sl.Debug {
return
}
displayError(logger.newLogEvent(data, logger.DebugHeader, sl.name, sl.output))
}
// Debugln takes a pointer subLogger struct, string and interface sends to newLogEvent
func Debugln(sl *subLogger, v ...interface{}) {
if sl == nil || !enabled() {
return
}
if !sl.Debug {
return
}
displayError(logger.newLogEvent(fmt.Sprintln(v...), logger.DebugHeader, sl.name, sl.output))
}
// Debugf takes a pointer subLogger struct, string & interface formats and sends to Info()
func Debugf(sl *subLogger, data string, v ...interface{}) {
if sl == nil || !enabled() {
return
}
if !sl.Debug {
return
}
Debug(sl, fmt.Sprintf(data, v...))
}
// Warn takes a pointer subLogger struct & string and sends to newLogEvent()
func Warn(sl *subLogger, data string) {
if sl == nil || !enabled() {
return
}
if !sl.Warn {
return
}
displayError(logger.newLogEvent(data, logger.WarnHeader, sl.name, sl.output))
}
// Warnln takes a pointer subLogger struct & interface formats and sends to newLogEvent()
func Warnln(sl *subLogger, v ...interface{}) {
if sl == nil || !enabled() {
return
}
if !sl.Warn {
return
}
displayError(logger.newLogEvent(fmt.Sprintln(v...), logger.WarnHeader, sl.name, sl.output))
}
// Warnf takes a pointer subLogger struct, string & interface formats and sends to Warn()
func Warnf(sl *subLogger, data string, v ...interface{}) {
if sl == nil || !enabled() {
return
}
if !sl.Warn {
return
}
Warn(sl, fmt.Sprintf(data, v...))
}
// Error takes a pointer subLogger struct & interface formats and sends to newLogEvent()
func Error(sl *subLogger, data ...interface{}) {
if sl == nil || !enabled() {
return
}
if !sl.Error {
return
}
displayError(logger.newLogEvent(fmt.Sprint(data...), logger.ErrorHeader, sl.name, sl.output))
}
// Errorln takes a pointer subLogger struct, string & interface formats and sends to newLogEvent()
func Errorln(sl *subLogger, v ...interface{}) {
if sl == nil || !enabled() {
return
}
if !sl.Error {
return
}
displayError(logger.newLogEvent(fmt.Sprintln(v...), logger.ErrorHeader, sl.name, sl.output))
}
// Errorf takes a pointer subLogger struct, string & interface formats and sends to Debug()
func Errorf(sl *subLogger, data string, v ...interface{}) {
if sl == nil || !enabled() {
return
}
if !sl.Error {
return
}
Error(sl, fmt.Sprintf(data, v...))
}
func displayError(err error) {
if err != nil {
log.Printf("Logger write error: %v\n", err)
}
}
func enabled() bool {
RWM.RLock()
defer RWM.RUnlock()
if GlobalLogConfig.Enabled == nil {
return false
}
return *GlobalLogConfig.Enabled
}