-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.go
80 lines (63 loc) · 1.47 KB
/
trace.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
73
74
75
76
77
78
79
80
package easyfl
import "fmt"
// GlobalDataNoTrace does not trace
type GlobalDataNoTrace struct {
glb interface{}
}
func NewGlobalDataNoTrace(glb interface{}) *GlobalDataNoTrace {
return &GlobalDataNoTrace{glb}
}
func (t *GlobalDataNoTrace) Data() interface{} {
return t.glb
}
func (t *GlobalDataNoTrace) Trace() bool {
return false
}
func (t *GlobalDataNoTrace) PutTrace(s string) {
panic("inconsistency: PutTrace should not be called for GlobalDataNoTrace")
}
// GlobalDataLog saves trace into the log
type GlobalDataLog struct {
glb interface{}
log []string
}
func NewGlobalDataLog(glb interface{}) *GlobalDataLog {
return &GlobalDataLog{
glb: glb,
log: make([]string, 0),
}
}
func (t *GlobalDataLog) Data() interface{} {
return t.glb
}
func (t *GlobalDataLog) Trace() bool {
return true
}
func (t *GlobalDataLog) PutTrace(s string) {
t.log = append(t.log, s)
}
func (t *GlobalDataLog) PrintLog() {
fmt.Printf("--- trace begin ---\n")
for i, s := range t.log {
fmt.Printf("%d: %s\n", i, s)
}
fmt.Printf("--- trace end ---\n")
}
// GlobalDataTracePrint just prints all trace messages
type GlobalDataTracePrint struct {
glb interface{}
}
func NewGlobalDataTracePrint(glb interface{}) *GlobalDataTracePrint {
return &GlobalDataTracePrint{
glb: glb,
}
}
func (t *GlobalDataTracePrint) Data() interface{} {
return t.glb
}
func (t *GlobalDataTracePrint) Trace() bool {
return true
}
func (t *GlobalDataTracePrint) PutTrace(s string) {
fmt.Printf("%s\n", s)
}