forked from aphistic/golf
/
log.go
158 lines (131 loc) · 5.75 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
package golf
import (
"fmt"
)
func (l *Logger) genMsg(attrs map[string]interface{}, level int, msg string, va ...interface{}) *Message {
newMsg := l.NewMessage()
newMsg.Level = level
if len(va) > 0 {
newMsg.ShortMessage = fmt.Sprintf(msg, va...)
} else {
newMsg.ShortMessage = msg
}
newMsg.Attrs = attrs
return newMsg
}
func (l *Logger) logMsg(attrs map[string]interface{}, level int, msg string, va ...interface{}) error {
newMsg := l.genMsg(attrs, level, msg, va...)
return l.client.QueueMsg(newMsg)
}
// Dbg logs message 'msg' at LEVEL_DBG level
func (l *Logger) Dbg(msg string) error {
return l.logMsg(nil, LEVEL_DBG, msg)
}
// Log a message at LEVEL_DBG with 'format' populated with values from 'va'
func (l *Logger) Dbgf(format string, va ...interface{}) error {
return l.logMsg(nil, LEVEL_DBG, format, va...)
}
// Log a message at LEVEL_DBG with 'format' populated with values from 'va'. The
// attributes from 'attrs' will be included with the message, overriding any that may
// be set at the Logger level
func (l *Logger) Dbgm(attrs map[string]interface{}, format string, va ...interface{}) error {
return l.logMsg(attrs, LEVEL_DBG, format, va...)
}
// Log a message 'msg' at LEVEL_INFO level
func (l *Logger) Info(msg string) error {
return l.logMsg(nil, LEVEL_INFO, msg)
}
// Log a message at LEVEL_INFO with 'format' populated with values from 'va'
func (l *Logger) Infof(format string, va ...interface{}) error {
return l.logMsg(nil, LEVEL_INFO, format, va...)
}
// Log a message at LEVEL_INFO with 'format' populated with values from 'va'. The
// attributes from 'attrs' will be included with the message, overriding any that may
// be set at the Logger level
func (l *Logger) Infom(attrs map[string]interface{}, format string, va ...interface{}) error {
return l.logMsg(attrs, LEVEL_INFO, format, va...)
}
// Log a message 'msg' at LEVEL_NOTICE level
func (l *Logger) Notice(msg string) error {
return l.logMsg(nil, LEVEL_NOTICE, msg)
}
// Log a message at LEVEL_NOTICE with 'format' populated with values from 'va'
func (l *Logger) Noticef(format string, va ...interface{}) error {
return l.logMsg(nil, LEVEL_NOTICE, format, va...)
}
// Log a message at LEVEL_NOTICE with 'format' populated with values from 'va'. The
// attributes from 'attrs' will be included with the message, overriding any that may
// be set at the Logger level
func (l *Logger) Noticem(attrs map[string]interface{}, format string, va ...interface{}) error {
return l.logMsg(attrs, LEVEL_NOTICE, format, va...)
}
// Log a message 'msg' at LEVEL_WARN level
func (l *Logger) Warn(msg string) error {
return l.logMsg(nil, LEVEL_WARN, msg)
}
// Log a message at LEVEL_WARN with 'format' populated with values from 'va'
func (l *Logger) Warnf(format string, va ...interface{}) error {
return l.logMsg(nil, LEVEL_WARN, format, va...)
}
// Log a message at LEVEL_WARN with 'format' populated with values from 'va'. The
// attributes from 'attrs' will be included with the message, overriding any that may
// be set at the Logger level
func (l *Logger) Warnm(attrs map[string]interface{}, format string, va ...interface{}) error {
return l.logMsg(attrs, LEVEL_WARN, format, va...)
}
// Log a message 'msg' at LEVEL_ERR level
func (l *Logger) Err(msg string) error {
return l.logMsg(nil, LEVEL_ERR, msg)
}
// Log a message at LEVEL_ERR with 'format' populated with values from 'va'
func (l *Logger) Errf(format string, va ...interface{}) error {
return l.logMsg(nil, LEVEL_ERR, format, va...)
}
// Log a message at LEVEL_ERR with 'format' populated with values from 'va'. The
// attributes from 'attrs' will be included with the message, overriding any that may
// be set at the Logger level
func (l *Logger) Errm(attrs map[string]interface{}, format string, va ...interface{}) error {
return l.logMsg(attrs, LEVEL_ERR, format, va...)
}
// Log a message 'msg' at LEVEL_CRIT level
func (l *Logger) Crit(msg string) error {
return l.logMsg(nil, LEVEL_CRIT, msg)
}
// Log a message at LEVEL_CRIT with 'format' populated with values from 'va'
func (l *Logger) Critf(format string, va ...interface{}) error {
return l.logMsg(nil, LEVEL_CRIT, format, va...)
}
// Log a message at LEVEL_CRIT with 'format' populated with values from 'va'. The
// attributes from 'attrs' will be included with the message, overriding any that may
// be set at the Logger level
func (l *Logger) Critm(attrs map[string]interface{}, format string, va ...interface{}) error {
return l.logMsg(attrs, LEVEL_CRIT, format, va...)
}
// Log a message 'msg' at LEVEL_ALERT level
func (l *Logger) Alert(msg string) error {
return l.logMsg(nil, LEVEL_ALERT, msg)
}
// Log a message at LEVEL_ALERT with 'format' populated with values from 'va'
func (l *Logger) Alertf(format string, va ...interface{}) error {
return l.logMsg(nil, LEVEL_ALERT, format, va...)
}
// Log a message at LEVEL_ALERT with 'format' populated with values from 'va'. The
// attributes from 'attrs' will be included with the message, overriding any that may
// be set at the Logger level
func (l *Logger) Alertm(attrs map[string]interface{}, format string, va ...interface{}) error {
return l.logMsg(attrs, LEVEL_ALERT, format, va...)
}
// Log a message 'msg' at LEVEL_EMERG level
func (l *Logger) Emerg(msg string) error {
return l.logMsg(nil, LEVEL_EMERG, msg)
}
// Log a message at LEVEL_EMERG with 'format' populated with values from 'va'
func (l *Logger) Emergf(format string, va ...interface{}) error {
return l.logMsg(nil, LEVEL_EMERG, format, va...)
}
// Log a message at LEVEL_EMERG with 'format' populated with values from 'va'. The
// attributes from 'attrs' will be included with the message, overriding any that may
// be set at the Logger level
func (l *Logger) Emergm(attrs map[string]interface{}, format string, va ...interface{}) error {
return l.logMsg(attrs, LEVEL_EMERG, format, va...)
}