mirror of
https://github.com/home-assistant/core.git
synced 2025-05-01 04:37:52 +00:00
Reduce system_log overhead (#96177)
This commit is contained in:
parent
1aefbd8b86
commit
1c54b2e025
@ -116,6 +116,19 @@ def _safe_get_message(record: logging.LogRecord) -> str:
|
|||||||
class LogEntry:
|
class LogEntry:
|
||||||
"""Store HA log entries."""
|
"""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:
|
def __init__(self, record: logging.LogRecord, source: tuple[str, int]) -> None:
|
||||||
"""Initialize a log entry."""
|
"""Initialize a log entry."""
|
||||||
self.first_occurred = self.timestamp = record.created
|
self.first_occurred = self.timestamp = record.created
|
||||||
@ -134,7 +147,7 @@ class LogEntry:
|
|||||||
self.root_cause = str(traceback.extract_tb(tb)[-1])
|
self.root_cause = str(traceback.extract_tb(tb)[-1])
|
||||||
self.source = source
|
self.source = source
|
||||||
self.count = 1
|
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):
|
def to_dict(self):
|
||||||
"""Convert object into dict to maintain backward compatibility."""
|
"""Convert object into dict to maintain backward compatibility."""
|
||||||
@ -160,7 +173,7 @@ class DedupStore(OrderedDict):
|
|||||||
|
|
||||||
def add_entry(self, entry: LogEntry) -> None:
|
def add_entry(self, entry: LogEntry) -> None:
|
||||||
"""Add a new entry."""
|
"""Add a new entry."""
|
||||||
key = entry.hash
|
key = entry.key
|
||||||
|
|
||||||
if key in self:
|
if key in self:
|
||||||
# Update stored entry
|
# Update stored entry
|
||||||
|
Loading…
x
Reference in New Issue
Block a user