Skip to content

Commit

Permalink
fix event log
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <[email protected]>
  • Loading branch information
hexian000 committed May 10, 2024
1 parent 56a10ee commit 6209310
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions v2/eventlog/eventlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,24 @@ func (p *recent) Add(timestamp time.Time, message string) {
p.mu.Lock()
defer p.mu.Unlock()
if len(p.elements) > 0 {
last := &p.elements[len(p.elements)-1]
pos := p.lastpos
if pos--; pos < 0 {
pos = len(p.elements) - 1
}
last := &p.elements[pos]
if last.message == message {
last.tstamp = timestamp
last.count++
return
}
}
element := entry{timestamp, message, 1}
if len(p.elements) < cap(p.elements) {
p.elements = append(p.elements, entry{timestamp, message, 1})
p.elements = append(p.elements, element)
p.lastpos = (p.lastpos + 1) % cap(p.elements)
return
}
p.elements[p.lastpos] = entry{timestamp, message, 1}
p.elements[p.lastpos] = element
p.lastpos = (p.lastpos + 1) % len(p.elements)
}

Expand Down

0 comments on commit 6209310

Please sign in to comment.