-
Notifications
You must be signed in to change notification settings - Fork 18
/
logging.go
41 lines (33 loc) · 1.07 KB
/
logging.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
package runscope
import (
"fmt"
"strings"
)
var (
debugHandler func(level int, format string, args ...interface{})
infoHandler func(level int, format string, args ...interface{})
errorHandler func(level int, format string, args ...interface{})
defaultHandler = func(level int, format string, args ...interface{}) {
fmt.Printf("[DEBUG]%s %s\n", strings.Repeat("\t", level-1), fmt.Sprintf(format, args...))
}
)
func init() {
RegisterLogHandlers(defaultHandler, defaultHandler, defaultHandler)
}
func RegisterLogHandlers(
debug func(level int, format string, args ...interface{}),
info func(level int, format string, args ...interface{}),
error func(level int, format string, args ...interface{})) {
debugHandler = debug
infoHandler = info
errorHandler = error
}
func DebugF(level int, format string, args ...interface{}) {
debugHandler(level, format, args...)
}
func InfoF(level int, format string, args ...interface{}) {
infoHandler(level, format, args...)
}
func ErrorF(level int, format string, args ...interface{}) {
errorHandler(level, format, args...)
}