-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.go
More file actions
87 lines (76 loc) · 1.96 KB
/
Copy pathdebug.go
File metadata and controls
87 lines (76 loc) · 1.96 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//go:build eng
// +build eng
package portal
import (
"fmt"
"os"
"time"
"github.com/FrameworkOSS/event"
)
func (opt *PortalOptions) GetLog() bool {
return opt.log
}
func (opt *PortalOptions) GetDebugger() string {
return opt.debugger
}
func (opt *PortalOptions) SetLog(log bool) *PortalOptions {
opt.log = log
return opt
}
func (opt *PortalOptions) SetDebugger(id string) *PortalOptions {
opt.debugger = id
return opt
}
func (opt *PortalOptions) stringDebug() (str string) {
str += fmt.Sprintf("Log:\t\t\t%t\n", opt.log)
return
}
func (p *Portal) Log(format string, vars ...any) {
log := p.OptionsGet().GetLog()
if !log {
return
}
p.LockKey(KEY_LOG)
if p.logfile == nil {
logname := p.id() + ".log"
p.logfile, _ = os.Create(logname)
}
format = fmt.Sprintf("%s: %s", p.id(), format)
if format[len(format)-1] != '\n' {
format += "\n"
}
format += "\n"
out := fmt.Sprintf(format, vars...)
p.logfile.WriteString(out)
p.UnlockKey(KEY_LOG)
}
// DebugEvent returns a string formatting of an event.
func DebugEvent(e *event.Event) (s string) {
s += "<<<< portal:" + e.GetPortal() + " producer:" + e.GetProducer() + " >>>>"
if epochMilli := e.GetEpochMilli(); epochMilli > 0 {
t := time.UnixMilli(int64(epochMilli))
s += fmt.Sprintf(" %s", t.Format(time.RFC3339Nano))
}
s += fmt.Sprintf("\nid:%s", event.Key(e.GetID()))
if channel := e.GetChannel(); channel != "" {
s += fmt.Sprintf(" (channel:%s)", channel)
}
if parts := e.GetParticipants(); len(parts) > 0 {
s += fmt.Sprintf(" targets:%v", parts)
}
s += "\n"
if offsets := e.GetOffsets(); len(offsets) > 0 {
s += fmt.Sprintf("Offsets: %v\n", e.GetOffsets())
}
if data := e.GetData(); len(data) > 0 {
s += "<<<\n"
switch e.GetID() {
case event.EVENT_RESPONSE, event.EVENT_ERROR:
s += string(data)
default:
s += fmt.Sprintf("0x%X\n===\n%s", data, string(data))
}
s += "\n>>>\n"
}
return s
}