Skip to content

Commit

Permalink
Calc log fix (#316)
Browse files Browse the repository at this point in the history
* fix status end

* add ordering event log

Co-authored-by: srliao <[email protected]>
  • Loading branch information
srliao and srliao authored Feb 24, 2022
1 parent 4240637 commit 8d19811
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 38 deletions.
29 changes: 17 additions & 12 deletions internal/eventlog/eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ type keyVal struct {

//easyjson:json
type Event struct {
Typ core.LogSource `json:"event"`
F int `json:"frame"`
Ended int `json:"ended"`
SrcChar int `json:"char_index"`
Msg string `json:"msg,nocopy"`
Logs map[string]interface{} `json:"logs"`
Typ core.LogSource `json:"event"`
F int `json:"frame"`
Ended int `json:"ended"`
SrcChar int `json:"char_index"`
Msg string `json:"msg,nocopy"`
Logs map[string]interface{} `json:"logs"`
Ordering map[string]int `json:"ordering"`
counter int
}

//easyjson:json
Expand All @@ -48,6 +50,8 @@ func (e *Event) Write(keysAndValues ...interface{}) {
// Val: keysAndValues[i],
// })
e.Logs[key] = keysAndValues[i]
e.Ordering[key] = e.counter
e.counter++
}
}

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

func (c *Ctrl) NewEvent(msg string, typ core.LogSource, srcChar int, keysAndValues ...interface{}) core.LogEvent {
e := &Event{
Msg: msg,
F: c.core.F,
Ended: c.core.F,
Typ: typ,
SrcChar: srcChar,
Logs: make(map[string]interface{}), //+5 from default just in case we need to add in more keys
Msg: msg,
F: c.core.F,
Ended: c.core.F,
Typ: typ,
SrcChar: srcChar,
Logs: make(map[string]interface{}), //+5 from default just in case we need to add in more keys
Ordering: make(map[string]int),
}
// c.events = append(c.events, e)
c.events[c.count] = e
Expand Down
79 changes: 58 additions & 21 deletions internal/eventlog/eventlog_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions internal/eventlog/eventlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@ func TestEventWriteNonStringKeyPanic(t *testing.T) {

func TestEventWriteKeyVal(t *testing.T) {
e := &Event{
Msg: "test",
F: 1,
Typ: core.LogCharacterEvent,
SrcChar: 0,
Logs: map[string]interface{}{},
Msg: "test",
F: 1,
Typ: core.LogCharacterEvent,
SrcChar: 0,
Logs: map[string]interface{}{},
Ordering: make(map[string]int),
}

//this should be ok no panic
Expand Down
1 change: 1 addition & 0 deletions internal/tmpl/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func (s *StatusCtrl) AddStatus(key string, dur int) {
//otherwise create a new event
a.evt = s.core.Log.NewEvent("status added: ", core.LogStatusEvent, -1, "key", key, "expiry", s.core.F+dur)
a.expiry = s.core.F + dur
a.evt.SetEnded(a.expiry)

s.status[key] = a
}
Expand Down

0 comments on commit 8d19811

Please sign in to comment.