forked from hekmon/hllogger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
203 lines (167 loc) · 4.78 KB
/
log.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
196
197
198
199
200
201
202
203
package hllogger
import (
"fmt"
)
/*
Output
*/
// Output is a wrapper to the log.Output() base fx
func (l *Logger) Output(message string) {
l.logger.Output(2, message)
}
// Outputf is a wrapper to the the Output() fx but with formating support
func (l *Logger) Outputf(format string, a ...interface{}) {
l.Output(fmt.Sprintf(format, a...))
}
/*
Debug
*/
// Debug logs a message at the Debug level
func (l *Logger) Debug(message string) {
if l.llevel >= LevelDebug {
l.Outputf("%s%9s: %s", l.getJournaldPrefix(LevelDebug), LevelDebug, message)
}
}
// Debugf logs a message at the Debug level with formating support
func (l *Logger) Debugf(format string, a ...interface{}) {
if l.llevel >= LevelDebug {
l.Debug(fmt.Sprintf(format, a...))
}
}
// IsDebugShown returns true if the Debug level is in use
func (l *Logger) IsDebugShown() (shown bool) {
return l.llevel >= LevelDebug
}
/*
Info
*/
// Info logs a message at the Info level
func (l *Logger) Info(message string) {
if l.llevel >= LevelInfo {
l.Outputf("%s%9s: %s", l.getJournaldPrefix(LevelInfo), LevelInfo, message)
}
}
// Infof logs a message at the Info level with formating support
func (l *Logger) Infof(format string, a ...interface{}) {
if l.llevel >= LevelInfo {
l.Info(fmt.Sprintf(format, a...))
}
}
// IsInfoShown returns true if the Info level is in use
func (l *Logger) IsInfoShown() (shown bool) {
return l.llevel >= LevelInfo
}
/*
Notice
*/
// Notice logs a message at the Notice level
func (l *Logger) Notice(message string) {
if l.llevel >= LevelNotice {
l.Outputf("%s%9s: %s", l.getJournaldPrefix(LevelNotice), LevelNotice, message)
}
}
// Noticef logs a message at the Notice level with formating support
func (l *Logger) Noticef(format string, a ...interface{}) {
if l.llevel >= LevelNotice {
l.Notice(fmt.Sprintf(format, a...))
}
}
// IsNoticeShown returns true if the Notice level is in use
func (l *Logger) IsNoticeShown() (shown bool) {
return l.llevel >= LevelNotice
}
/*
Warning
*/
// Warning logs a message at the Warning level
func (l *Logger) Warning(message string) {
if l.llevel >= LevelWarning {
l.Outputf("%s%9s: %s", l.getJournaldPrefix(LevelWarning), LevelWarning, message)
}
}
// Warningf logs a message at the Warning level with formating support
func (l *Logger) Warningf(format string, a ...interface{}) {
if l.llevel >= LevelWarning {
l.Warning(fmt.Sprintf(format, a...))
}
}
// IsWarningShown returns true if the Warning level is in use
func (l *Logger) IsWarningShown() (shown bool) {
return l.llevel >= LevelWarning
}
/*
Error
*/
// Error logs a message at the Error level
func (l *Logger) Error(message string) {
if l.llevel >= LevelError {
l.Outputf("%s%9s: %s", l.getJournaldPrefix(LevelError), LevelError, message)
}
}
// Errorf logs a message at the Error level with formating support
func (l *Logger) Errorf(format string, a ...interface{}) {
if l.llevel >= LevelError {
l.Error(fmt.Sprintf(format, a...))
}
}
// IsErrorShown returns true if the Error level is in use
func (l *Logger) IsErrorShown() (shown bool) {
return l.llevel >= LevelError
}
/*
Critical
*/
// Critical logs a message at the Critical level
func (l *Logger) Critical(message string) {
if l.llevel >= LevelCritical {
l.Outputf("%s%9s: %s", l.getJournaldPrefix(LevelCritical), LevelCritical, message)
}
}
// Criticalf logs a message at the Critical level with formating support
func (l *Logger) Criticalf(format string, a ...interface{}) {
if l.llevel >= LevelCritical {
l.Critical(fmt.Sprintf(format, a...))
}
}
// IsCriticalShown returns true if the Critical level is in use
func (l *Logger) IsCriticalShown() (shown bool) {
return l.llevel >= LevelCritical
}
/*
Alert
*/
// Alert logs a message at the Alert level
func (l *Logger) Alert(message string) {
if l.llevel >= LevelAlert {
l.Outputf("%s%9s: %s", l.getJournaldPrefix(LevelAlert), LevelAlert, message)
}
}
// Alertf logs a message at the Alert level with formating support
func (l *Logger) Alertf(format string, a ...interface{}) {
if l.llevel >= LevelAlert {
l.Alert(fmt.Sprintf(format, a...))
}
}
// IsAlertShown returns true if the Alert level is in use
func (l *Logger) IsAlertShown() (shown bool) {
return l.llevel >= LevelAlert
}
/*
Emergency
*/
// Emergency logs a message at the XXX level
func (l *Logger) Emergency(message string) {
if l.llevel >= LevelEmergency {
l.Outputf("%s%9s: %s", l.getJournaldPrefix(LevelEmergency), LevelEmergency, message)
}
}
// Emergencyf logs a message at the Emergency level with formating support
func (l *Logger) Emergencyf(format string, a ...interface{}) {
if l.llevel >= LevelEmergency {
l.Emergency(fmt.Sprintf(format, a...))
}
}
// IsEmergencyShown returns true if the Emergency level is in use
func (l *Logger) IsEmergencyShown() (shown bool) {
return l.llevel >= LevelEmergency
}