Skip to content

Commit

Permalink
Log viewer: fix old data returned when count set
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Apr 15, 2024
1 parent 507dcc4 commit 535c94c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions util/logstash/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ func (l *logger) All(areas []string, level jww.Threshold, count int) []string {
r = r.Next()
if e, ok := r.Value.(element); ok && e != "" && (all || e.match(areas, level)) {
res = append(res, string(e))
if count > 0 && len(res) >= count {
break
}
}
}

if count > 0 && len(res) >= count {
res = res[len(res)-count:]
}

return res
}
2 changes: 2 additions & 0 deletions util/logstash/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ func TestLog(t *testing.T) {

assert.Equal(t, []string{s1, s3}, log.All([]string{"test1"}, jww.LevelTrace, 0))
assert.Equal(t, []string{s1, s2, s3}, log.All(nil, jww.LevelTrace, 0))
assert.Equal(t, []string{s3}, log.All(nil, jww.LevelTrace, 1))

assert.Nil(t, log.All(nil, jww.LevelFatal, 0))

assert.Equal(t, idx, log.data, "data should not be changed after All() call")
Expand Down

0 comments on commit 535c94c

Please sign in to comment.