"""How a node says things to its journal.
These two lived in app.py, where a compartment could not reach them without
importing the node that imports the compartment. They are not the node's:
they are how anything in the node writes a line an operator will read.
"""
from __future__ import annotations
import sys
import time
from typing import Any
[docs]def line(*parts: Any) -> None:
"""One timestamped line on stderr, flushed.
A node runs under systemd, where both streams are the journal, and the
first deployment of two of these found them completely silent: `journalctl
-u meshnode` held one line, the one systemd wrote itself. An operator could
not tell whether the node had peered, pulled, been declined or crashed
without reading a JSON file it had never been told about. A daemon that
does work says what it did.
It says it on **stderr**, and that is not cosmetic. It used to go to
stdout, which is also where `meshnode <cmd> --json` writes its answer, and
a node busy enough to say something while a command was answering put a
line like
2026-09-05T21:56:24Z < acked-out 67dd799a6be0… accepted
[{"epoch": 496527, ...}]
on one stream. The reader got `Extra data: line 1 column 5`. fleetmesh_node/README.md
offers `--json` and the control socket to "a dashboard, a metrics exporter,
a fleet script"; a stream that is usually parseable is not an API. So
stdout is the answer to what was asked, stderr is the running commentary,
and systemd captures both exactly as before.
"""
print('%s %s' % (time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
' '.join(str(p) for p in parts)), file=sys.stderr, flush=True)
[docs]def short(x: Any) -> str:
"""Long hex is unreadable in a log and its first bytes identify it."""
s = str(x)
return s[:12] + '…' if len(s) > 16 and all(c in '0123456789abcdef' for c in s) else s