-
Notifications
You must be signed in to change notification settings - Fork 113
/
type.go
59 lines (53 loc) · 999 Bytes
/
type.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
package ilog
// Level is the log level.
type Level int
// log level enum.
const (
LevelDebug Level = iota
LevelInfo
LevelWarn
LevelError
LevelFatal
)
// NewLevel will return a new level by name
func NewLevel(l string) Level {
switch l {
case "debug":
return LevelDebug
case "info":
return LevelInfo
case "warn":
return LevelWarn
case "error":
return LevelError
case "fatal":
return LevelFatal
default:
return LevelDebug
}
}
var (
levelBytes = map[Level][]byte{
LevelDebug: []byte("Debug"),
LevelInfo: []byte("Info"),
LevelWarn: []byte("Warn"),
LevelError: []byte("Error"),
LevelFatal: []byte("Fatal"),
}
levelColor = map[Level]int{
LevelDebug: 32, // green
LevelInfo: 34, // blue
LevelWarn: 33, // yellow
LevelError: 31, // red
LevelFatal: 35, // magenta
}
)
// LogWriter defines writer's API.
type LogWriter interface {
Init() error
SetLevel(Level)
GetLevel() Level
Write(msg string, level Level) error
Flush() error
Close() error
}