-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
59 lines (50 loc) · 947 Bytes
/
logger.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 logx
import "strings"
const (
LEVEL_DEBUG LogLevel = iota - 1
LEVEL_INFO
LEVEL_WARN
LEVEL_ERROR
)
type LogLevel int8
func (l LogLevel) Int() int {
return int(l)
}
func (l LogLevel) String() string {
switch l {
case LEVEL_DEBUG:
return "DEBUG"
case LEVEL_INFO:
return "INFO"
case LEVEL_WARN:
return "WARN"
case LEVEL_ERROR:
return "ERROR"
default:
return "INFO"
}
}
func ParseLogLevel(s string) LogLevel {
switch strings.ToUpper(s) {
case "DEBUG":
return LEVEL_DEBUG
case "INFO":
return LEVEL_INFO
case "WARN":
return LEVEL_WARN
case "ERROR":
return LEVEL_ERROR
}
return LEVEL_INFO
}
type Logger interface {
SetLevel(level string)
Debug(v ...interface{})
Info(v ...interface{})
Warn(v ...interface{})
Error(v ...interface{})
Debugf(format string, v ...interface{})
Infof(format string, v ...interface{})
Warnf(format string, v ...interface{})
Errorf(format string, v ...interface{})
}