-
Notifications
You must be signed in to change notification settings - Fork 4
/
debug.go
72 lines (64 loc) · 1.48 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
66
67
68
69
70
71
72
package main
import (
"fmt"
"math/rand"
"runtime"
"strconv"
)
const (
debugNone = 0
debugIO = 1
debugQuery = 2
debugDecorateFunctionName = 14
debugAddFunctionName = 15
)
//const DebugLevel uint32 = debugIO | (1<<debugAddFunctionName-1)
const DebugLevel uint32 = debugNone
func debugIOPrintf(format string, a ...interface{}) (int, error) {
var s, randomSeed string
var n int
var err error
randomSeed = ""
if DebugLevel&(1<<(debugIO-1)) != 0 {
if DebugLevel&(1<<(debugAddFunctionName-1)) != 0 {
pc, _, _, ok := runtime.Caller(1)
s = "?"
if ok {
fn := runtime.FuncForPC(pc)
if fn != nil {
s = fn.Name()
}
}
if DebugLevel&(1<<(debugDecorateFunctionName-1)) != 0 {
randomSeed = "." + strconv.Itoa(rand.Intn(10000))
}
newformat := "[" + s + randomSeed + "] " + format
n, err = fmt.Printf(newformat, a...)
} else {
n, err = fmt.Printf(format, a...)
}
return n, err
}
return 0, nil
}
func debugIOPrintln(a ...interface{}) (int, error) {
if DebugLevel&(1<<(debugIO-1)) != 0 {
n, err := fmt.Println(a...)
return n, err
}
return 0, nil
}
func debugQueryPrintf(format string, a ...interface{}) (int, error) {
if DebugLevel&(1<<(debugQuery-1)) != 0 {
n, err := fmt.Printf(format, a...)
return n, err
}
return 0, nil
}
func debugQueryPrintln(a ...interface{}) (int, error) {
if DebugLevel&(1<<(debugQuery-1)) != 0 {
n, err := fmt.Println(a...)
return n, err
}
return 0, nil
}