Skip to content

Commit 8d19811

Browse files
authored
Calc log fix (#316)
* fix status end * add ordering event log Co-authored-by: srliao <[email protected]>
1 parent 4240637 commit 8d19811

File tree

4 files changed

+82
-38
lines changed

4 files changed

+82
-38
lines changed

internal/eventlog/eventlog.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ type keyVal struct {
1818

1919
//easyjson:json
2020
type Event struct {
21-
Typ core.LogSource `json:"event"`
22-
F int `json:"frame"`
23-
Ended int `json:"ended"`
24-
SrcChar int `json:"char_index"`
25-
Msg string `json:"msg,nocopy"`
26-
Logs map[string]interface{} `json:"logs"`
21+
Typ core.LogSource `json:"event"`
22+
F int `json:"frame"`
23+
Ended int `json:"ended"`
24+
SrcChar int `json:"char_index"`
25+
Msg string `json:"msg,nocopy"`
26+
Logs map[string]interface{} `json:"logs"`
27+
Ordering map[string]int `json:"ordering"`
28+
counter int
2729
}
2830

2931
//easyjson:json
@@ -48,6 +50,8 @@ func (e *Event) Write(keysAndValues ...interface{}) {
4850
// Val: keysAndValues[i],
4951
// })
5052
e.Logs[key] = keysAndValues[i]
53+
e.Ordering[key] = e.counter
54+
e.counter++
5155
}
5256
}
5357

@@ -96,12 +100,13 @@ func (c *Ctrl) NewEventBuildMsg(typ core.LogSource, srcChar int, msg ...string)
96100

97101
func (c *Ctrl) NewEvent(msg string, typ core.LogSource, srcChar int, keysAndValues ...interface{}) core.LogEvent {
98102
e := &Event{
99-
Msg: msg,
100-
F: c.core.F,
101-
Ended: c.core.F,
102-
Typ: typ,
103-
SrcChar: srcChar,
104-
Logs: make(map[string]interface{}), //+5 from default just in case we need to add in more keys
103+
Msg: msg,
104+
F: c.core.F,
105+
Ended: c.core.F,
106+
Typ: typ,
107+
SrcChar: srcChar,
108+
Logs: make(map[string]interface{}), //+5 from default just in case we need to add in more keys
109+
Ordering: make(map[string]int),
105110
}
106111
// c.events = append(c.events, e)
107112
c.events[c.count] = e

internal/eventlog/eventlog_easyjson.go

Lines changed: 58 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/eventlog/eventlog_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,12 @@ func TestEventWriteNonStringKeyPanic(t *testing.T) {
4949

5050
func TestEventWriteKeyVal(t *testing.T) {
5151
e := &Event{
52-
Msg: "test",
53-
F: 1,
54-
Typ: core.LogCharacterEvent,
55-
SrcChar: 0,
56-
Logs: map[string]interface{}{},
52+
Msg: "test",
53+
F: 1,
54+
Typ: core.LogCharacterEvent,
55+
SrcChar: 0,
56+
Logs: map[string]interface{}{},
57+
Ordering: make(map[string]int),
5758
}
5859

5960
//this should be ok no panic

internal/tmpl/status/status.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func (s *StatusCtrl) AddStatus(key string, dur int) {
5151
//otherwise create a new event
5252
a.evt = s.core.Log.NewEvent("status added: ", core.LogStatusEvent, -1, "key", key, "expiry", s.core.F+dur)
5353
a.expiry = s.core.F + dur
54+
a.evt.SetEnded(a.expiry)
5455

5556
s.status[key] = a
5657
}

0 commit comments

Comments
 (0)