-
Notifications
You must be signed in to change notification settings - Fork 5
/
log.go
63 lines (50 loc) · 1.25 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
package xingyun
import (
"io"
"log"
)
type Logger interface {
Infof(s string, o ...interface{})
Errorf(s string, o ...interface{})
Debugf(s string, o ...interface{})
Warnf(s string, o ...interface{})
Tracef(s string, o ...interface{})
}
type debugLogger struct {
Logger
enableDebug bool
}
func (l *debugLogger) Debugf(s string, o ...interface{}) {
if l.enableDebug {
l.Logger.Debugf(s, o...)
}
}
func (l *debugLogger) Tracef(s string, o ...interface{}) {
if l.enableDebug {
l.Logger.Tracef(s, o...)
}
}
type simpleLevelLogger struct {
l *log.Logger
}
func NewSimpleLevelLogger(w io.Writer) *simpleLevelLogger {
return &simpleLevelLogger{log.New(w, "", log.LstdFlags)}
}
func (l *simpleLevelLogger) output(level, s string, o ...interface{}) {
log.Printf(level+" "+s, o...)
}
func (l *simpleLevelLogger) Infof(s string, o ...interface{}) {
l.output("INFO", s, o...)
}
func (l *simpleLevelLogger) Errorf(s string, o ...interface{}) {
l.output("ERROR", s, o...)
}
func (l *simpleLevelLogger) Warnf(s string, o ...interface{}) {
l.output("WARN", s, o...)
}
func (l *simpleLevelLogger) Debugf(s string, o ...interface{}) {
l.output("DEBUG", s, o...)
}
func (l *simpleLevelLogger) Tracef(s string, o ...interface{}) {
l.output("TRACE", s, o...)
}