better cloud logging

This commit is contained in:
2026-08-26 18:35:33 +02:00
parent 1e73476830
commit f431432eb0
3 changed files with 17 additions and 3 deletions
+9 -1
View File
@@ -36,7 +36,15 @@ def _tail(path: Path, line_count: int = 50) -> str:
logfile.seek(end)
data = logfile.read(size) + data
return b"\n".join(data.splitlines()[-line_count:]).decode("utf-8", "replace")
output = []
for raw_line in data.splitlines()[-line_count:]:
line = raw_line.decode("utf-8", "replace")
try:
event = json.loads(line).get("event", {})
output.append(str(event["text"]))
except (json.JSONDecodeError, AttributeError, KeyError, TypeError):
output.append(line)
return "\n".join(output)
except FileNotFoundError:
return ""