ordered by last occurence (#21200)
This commit is contained in:
parent
99eda385d1
commit
b0f317743b
2 changed files with 12 additions and 3 deletions
|
@ -88,7 +88,7 @@ class LogEntry:
|
|||
|
||||
def __init__(self, record, stack, source):
|
||||
"""Initialize a log entry."""
|
||||
self.timestamp = record.created
|
||||
self.first_occured = self.timestamp = record.created
|
||||
self.level = record.levelname
|
||||
self.message = record.getMessage()
|
||||
if record.exc_info:
|
||||
|
@ -125,9 +125,13 @@ class DedupStore(OrderedDict):
|
|||
key = str(entry.hash())
|
||||
|
||||
if key in self:
|
||||
entry.count = self[key].count + 1
|
||||
# Update stored entry
|
||||
self[key].count += 1
|
||||
self[key].timestamp = entry.timestamp
|
||||
|
||||
self[key] = entry
|
||||
self.move_to_end(key)
|
||||
else:
|
||||
self[key] = entry
|
||||
|
||||
if len(self) > self.maxlen:
|
||||
# Removes the first record which should also be the oldest
|
||||
|
|
|
@ -152,6 +152,11 @@ async def test_dedup_logs(hass, hass_client):
|
|||
assert log[1]["count"] == 2
|
||||
assert_log(log[1], '', 'error message 2', 'ERROR')
|
||||
|
||||
_LOGGER.error('error message 2')
|
||||
log = await get_error_log(hass, hass_client, 2)
|
||||
assert_log(log[0], '', 'error message 2', 'ERROR')
|
||||
assert log[0]["timestamp"] > log[0]["first_occured"]
|
||||
|
||||
|
||||
async def test_clear_logs(hass, hass_client):
|
||||
"""Test that the log can be cleared via a service call."""
|
||||
|
|
Loading…
Add table
Reference in a new issue