better cloud logging
This commit is contained in:
@@ -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 ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user