Reduce system_log overhead (#96177)
parent
1aefbd8b86
commit
1c54b2e025
|
@ -116,6 +116,19 @@ def _safe_get_message(record: logging.LogRecord) -> str:
|
|||
class LogEntry:
|
||||
"""Store HA log entries."""
|
||||
|
||||
__slots__ = (
|
||||
"first_occurred",
|
||||
"timestamp",
|
||||
"name",
|
||||
"level",
|
||||
"message",
|
||||
"exception",
|
||||
"root_cause",
|
||||
"source",
|
||||
"count",
|
||||
"key",
|
||||
)
|
||||
|
||||
def __init__(self, record: logging.LogRecord, source: tuple[str, int]) -> None:
|
||||
"""Initialize a log entry."""
|
||||
self.first_occurred = self.timestamp = record.created
|
||||
|
@ -134,7 +147,7 @@ class LogEntry:
|
|||
self.root_cause = str(traceback.extract_tb(tb)[-1])
|
||||
self.source = source
|
||||
self.count = 1
|
||||
self.hash = str([self.name, *self.source, self.root_cause])
|
||||
self.key = (self.name, source, self.root_cause)
|
||||
|
||||
def to_dict(self):
|
||||
"""Convert object into dict to maintain backward compatibility."""
|
||||
|
@ -160,7 +173,7 @@ class DedupStore(OrderedDict):
|
|||
|
||||
def add_entry(self, entry: LogEntry) -> None:
|
||||
"""Add a new entry."""
|
||||
key = entry.hash
|
||||
key = entry.key
|
||||
|
||||
if key in self:
|
||||
# Update stored entry
|
||||
|
|
Loading…
Reference in New Issue