-
Notifications
You must be signed in to change notification settings - Fork 182
/
logger.go
48 lines (38 loc) · 867 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
package iavl
const (
FlagOutputModules = "iavl-output-modules"
)
const (
IavlErr = 0
IavlInfo = 1
IavlDebug = 2
)
var (
logFunc LogFuncType = nil
OutputModules map[string]int
iavlLogger logger
)
type logger interface {
Debug(msg string, keyvals ...interface{})
Info(msg string, keyvals ...interface{})
Error(msg string, keyvals ...interface{})
}
type LogFuncType func(level int, format string, args ...interface{})
func SetLogFunc(l LogFuncType) {
logFunc = l
}
func SetLogger(l logger) {
iavlLogger = l
}
func iavlLog(module string, level int, msg string, keyvals ...interface{}) {
if v, ok := OutputModules[module]; ok && v != 0 && iavlLogger != nil {
switch level {
case IavlErr:
iavlLogger.Error(msg, keyvals...)
case IavlInfo:
iavlLogger.Info(msg, keyvals...)
case IavlDebug:
iavlLogger.Debug(msg, keyvals...)
}
}
}