-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
57 lines (50 loc) · 1.08 KB
/
debug.go
File metadata and controls
57 lines (50 loc) · 1.08 KB
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
package main
import (
"fmt"
"os"
"runtime"
"strings"
)
type DebugLevels struct {
Value int
Label string
}
var (
levelPanic = DebugLevels{0, "Panic "}
levelError = DebugLevels{1, "Error "}
levelWarning = DebugLevels{2, "Warning"}
levelNotice = DebugLevels{3, "Notice "}
levelInfo = DebugLevels{4, "Info "}
levelDebug = DebugLevels{5, "Debug "}
levelCrazy = DebugLevels{6, "Crazy "}
)
var DebugLevel int
var Dacl string
type PrintFunc func(format string, a ...interface{})
func debugPrint(printFunc PrintFunc, level DebugLevels, format string, a ...interface{}) {
var s string
if level.Value <= DebugLevel {
pc, _, _, ok := runtime.Caller(1)
s = "?"
if ok {
fn := runtime.FuncForPC(pc)
if fn != nil {
s = fn.Name()
}
}
newformat := fmt.Sprintf("(%s)["+s+"] ", level.Label) + format
if Dacl == "All" {
printFunc(newformat, a...)
} else {
fncs := strings.Split(Dacl, ",")
for _, fnc := range fncs {
if strings.HasSuffix(s, fnc) {
printFunc(newformat, a...)
}
}
}
if level.Value == 0 {
os.Exit(-1)
}
}
}