Bugfix: Non-UTF8-Characters in journal logs crashed
This commit is contained in:
parent
4f8fc0f361
commit
814cd7f3e7
1 changed files with 10 additions and 2 deletions
|
|
@ -44,7 +44,9 @@ def format_entries(entries: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||||
Entries without a realtime timestamp are dropped. The local time is
|
Entries without a realtime timestamp are dropped. The local time is
|
||||||
formatted as HH:MM:SS (invalid timestamps render as an empty string),
|
formatted as HH:MM:SS (invalid timestamps render as an empty string),
|
||||||
PRIORITY defaults to 6 (info), and the identifier falls back
|
PRIORITY defaults to 6 (info), and the identifier falls back
|
||||||
SYSLOG_IDENTIFIER -> _COMM -> _PID.
|
SYSLOG_IDENTIFIER -> _COMM -> _PID. A MESSAGE that is a JSON array —
|
||||||
|
journald encodes non-UTF-8 payloads as byte lists and multi-value
|
||||||
|
fields as string lists — is decoded or joined into a single line.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
entries: dicts from parse_lines.
|
entries: dicts from parse_lines.
|
||||||
|
|
@ -67,7 +69,13 @@ def format_entries(entries: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||||
prio = int(e.get("PRIORITY", "6"))
|
prio = int(e.get("PRIORITY", "6"))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
prio = 6
|
prio = 6
|
||||||
msg = e.get("MESSAGE", "").rstrip("\n")
|
raw_msg: str | list[Any] | None = e.get("MESSAGE")
|
||||||
|
if isinstance(raw_msg, list):
|
||||||
|
if raw_msg and all(isinstance(m, int) for m in raw_msg):
|
||||||
|
raw_msg = bytes(raw_msg).decode("utf-8", errors="replace")
|
||||||
|
else:
|
||||||
|
raw_msg = " ".join(str(m) for m in raw_msg)
|
||||||
|
msg = (raw_msg or "").rstrip("\n")
|
||||||
out.append(
|
out.append(
|
||||||
{
|
{
|
||||||
"stamp": stamp,
|
"stamp": stamp,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue