forked from dustin/go-coap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.go
65 lines (54 loc) · 1.05 KB
/
debug.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 coap
import (
"log"
)
const (
LevelEmergency = iota
LevelAlert
LevelCritical
LevelError
LevelWarning
LevelNotice
LevelInformational
LevelDebug
)
var debugEnable bool
var healthMonitorEnable bool
type TraceFunc func(format string, level int, v ...interface{})
var UserTrace TraceFunc = nil
func init() {
debugEnable = false
healthMonitorEnable = false
}
// Debug Enable debug
func Debug(enable bool) {
debugEnable = enable
}
// HealthMonitor Enable health monitor
func HealthMonitor(enable bool) {
healthMonitorEnable = enable
}
// SetUserDebug 配置其他日志输出
func SetUserDebug(f TraceFunc) {
UserTrace = f
}
// TraceInfo 调试信息日志
func TraceInfo(format string, v ...interface{}) {
if debugEnable {
if UserTrace != nil {
UserTrace(format, LevelInformational, v...)
} else {
log.Printf(format, v...)
}
}
}
// TraceError 错误日志
func TraceError(format string, v ...interface{}) {
if debugEnable {
if UserTrace != nil {
UserTrace(format, LevelError, v...)
} else {
log.Printf(format, v...)
}
}
}