-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracing.go
58 lines (52 loc) · 1.08 KB
/
tracing.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
package glog
import (
"strings"
)
type TraceLine struct {
Index int
Depth int
MaxDepth int
Function string
Path string
Line int
Prefix string
Logger *Logger
}
// Related config setting(s):
//
// - `LoggerConfig.ColorIndicatorDebug`
func (tl *TraceLine) Print(i, l, level, maxLenFunction, maxLenPath, maxLenLine int) {
d := int(tl.Index - tl.Depth)
pad := ""
if d > 0 {
if d == 1 {
pad = strings.Repeat(" ", 1)
} else {
pad = strings.Repeat(" ", d*4-3)
}
}
c := LoggerConfig.ColorIndicatorDebug - level - d
tl.Logger.write('t', "%s %s %s %s:%s",
Wrap(pad+tl.Prefix, c),
Auto(tl.Function),
Wrap(strings.Repeat("∙", maxLenFunction+(l-i)*4-len(tl.Function)-6), c),
File(tl.Path),
Int(tl.Line),
)
}
func NewTraceLine(l *Logger, i, depth, maxDepth int, function, path string, line int) *TraceLine {
prefix := "└──"
if i == depth {
prefix = ""
}
return &TraceLine{
Index: i,
Depth: Max(2, depth),
MaxDepth: Max(3, maxDepth),
Function: function,
Path: path,
Line: line,
Prefix: prefix,
Logger: l,
}
}