-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
65 lines (53 loc) · 1.09 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
package eyego
import "io"
import "log"
type LogLevel struct {
level int
name string
}
var (
TRACE = LogLevel{level:0, name:"TRACE"}
DEBUG = LogLevel{level:1, name:"DEBUG"}
INFO = LogLevel{level:2, name:"INFO"}
WARN = LogLevel{level:3, name:"WARN"}
ERROR = LogLevel{level:4, name:"ERROR"}
levels = []LogLevel{TRACE,DEBUG,INFO,WARN,ERROR}
level int
)
func LogLevelFromName(name string) LogLevel{
for i := range levels {
if levels[i].name == name {
return levels[i]
}
}
panic("No such level")
}
func Init(w io.Writer, _level LogLevel) {
log.SetOutput(w)
level = _level.level
}
func Trace(s string, args ...interface {}) {
if level <= TRACE.level {
log.Printf(s, args...)
}
}
func Debug(s string, args ...interface {}) {
if level <= DEBUG.level {
log.Printf(s, args...)
}
}
func Info(s string, args ...interface {}) {
if level <= INFO.level {
log.Printf(s, args...)
}
}
func Warn(s string, args ...interface {}) {
if level <= WARN.level {
log.Printf(s, args...)
}
}
func LogError(s string, args ...interface {}) {
if level <= ERROR.level {
log.Printf(s, args...)
}
}