-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.go
42 lines (34 loc) · 772 Bytes
/
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
package bot
import "fmt"
type ErrorLevel int
// Error level in order of value Error < Info < Warn < Debug
const (
Error ErrorLevel = iota
Info
Warn
Debug
)
type LogRecord struct {
Message string
Level ErrorLevel
}
func (l LogRecord) String() string {
var levelStr string
switch l.Level {
case Error:
levelStr = "ERROR"
case Info:
levelStr = "INFO"
case Warn:
levelStr = "WARN"
case Debug:
levelStr = "DEBUG"
}
return fmt.Sprintf("[%s][bot] %s", levelStr, l.Message)
}
// Log function that will be called for logging. By default it's null logger, client can override this
// to implement their logging of their choice
var Log = func(record LogRecord) {}
func log(level ErrorLevel, msg string) {
Log(LogRecord{Level: level, Message: msg})
}