Log viewer: fix old data returned when count set
This commit is contained in:
parent
507dcc4b60
commit
535c94c2fe
2 changed files with 6 additions and 3 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue