Skip to content

Commit

Permalink
Add trace data to record
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Apr 13, 2024
1 parent b2f5c81 commit 804b94f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions custom_components/hass_diagnostics/core/smart_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ def convert_log_entry_to_record(entry: dict):
"levelname": entry["level"],
"created": entry["timestamp"],
"pathname": entry["source"][0],
"lineno": entry["source"][1],
"message": entry["message"][0],
"exc_info": entry["exception"] != "",
"exc_text": entry["exception"],
Expand Down
14 changes: 13 additions & 1 deletion custom_components/hass_diagnostics/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,21 @@ def emit(self, record: logging.LogRecord, count: int = 1):
if item := self.records.get(key):
item["count"] += count
else:
entry["count"] = count
if record.exc_text:
entry["exception"] = record.exc_text
if hasattr(record, "funcName"):
entry["source"] = [
record.pathname,
record.lineno,
record.processName,
record.threadName,
record.funcName,
]
else:
entry["source"] = [record.pathname, record.lineno]
if github := github_get_link(record):
entry["github"] = github
entry["count"] = count
self.records[key] = entry

self._attr_native_value += count
Expand Down

0 comments on commit 804b94f

Please sign in to comment.