Files
GeuReflector/docs/LOGGING.md
T
Audric efa02459e9 logging: address code-review feedback
- Fix a critical regression where startup errors emitted before
  geulog::configure() (bad --config path, unknown CLI flag, --version
  banner) were queued into the async deque with no running worker
  and silently dropped on exit(). detail::enqueue() now falls back to
  synchronous ::write() to stdout/stderr when the worker is inactive.
- Remove the dead TRUNK_DEBUG parse block in Reflector.cpp and the
  m_trunk_debug member in Reflector.h — all gates were already
  removed in Phase 1; only the (unread) parse remained.
- Replace the #TRUNK_DEBUG=0 comment in svxreflector.conf.in with a
  documented LOG= reference block.
- Restore the [host:port] peer identity on the ReflectorClient
  ENOTCONN debug line so sysops can still correlate failures.
- Revert sighup_handler and sigterm_handler to async-signal-safe
  ::write(STDERR_FILENO, ...) instead of calling the (mutex-taking,
  allocating) facade from signal context.
- Retag two MsgTrunk* diagnostic sites in ReflectorMsg.h from core
  to trunk to match the enclosing-class rule.
- Doc: note that argument expressions are evaluated at the call site
  before the shouldLog() gate runs, and reword the "never drops"
  claim to acknowledge rare short-write truncation.
2026-04-18 21:02:42 +02:00

7.5 KiB
Raw Blame History

Logging

GeuReflector has a leveled, per-subsystem, live-reloadable logger. This document is for sysops who need to tune verbosity or diagnose a running reflector without restarting it.

Quick start

# In svxreflector.conf, under [GLOBAL]:
LOG=*=warn,trunk=debug,mqtt=info

Runtime control via the existing command PTY:

# Read current per-subsystem levels
echo "LOG SHOW"            > /dev/shm/reflector_ctrl

# Turn one subsystem verbose (and read back the ack)
echo "LOG trunk=debug"     > /dev/shm/reflector_ctrl

# Quiet everything
echo "LOG *=warn"          > /dev/shm/reflector_ctrl

# Back to whatever svxreflector.conf set at startup
echo "LOG RESET"           > /dev/shm/reflector_ctrl

Omit the LOG= tag entirely to keep today's behaviour — the default is *=info for every subsystem.


Levels

Five levels plus off. Each threshold admits itself and everything noisier above it.

Level Typical use
trace Finest-grained dev diagnostics (not widely used)
debug Diagnostic output for one subsystem — usually set temporarily
info Narrative events (connections, talker changes, reloads)
warn Non-fatal anomalies (reject bad config line, retry transient)
error Faults that block a specific operation
off Suppress entirely

Line format on the wire:

[debug] [trunk] peer LU-MOBILE handshake nonce=0x4f3a...

When the reflector is started with --logfile /var/log/svxreflector.log (or syslog), the existing LogWriter prepends a timestamp to each line before writing:

Apr 18 14:23:05 [debug] [trunk] peer LU-MOBILE handshake nonce=0x4f3a...

Subsystems

Tag Covers
trunk TrunkLink — peer handshake, talker arbitration, audio relay
satellite SatelliteLink / SatelliteClient — one-way mirror paths
twin Twin-pair (HA) protocol — audio mirror, stale-inbound cleanup
client Per-node TCP/UDP — auth, TLS handshake, RX, sendMsg
mqtt MQTT publisher — connect, publish, subscribe, lifecycle
redis Redis store / publisher — connect, read, write, lifecycle
core Coordinator glue — startup, config, HTTP /status, PTY, TGHandler

When a log line touches both a sink and a peer (e.g. publishing a trunk-talker event to MQTT), it is tagged with the sink (mqtt) — because that matches what a sysop saying "verbose for mqtt" wants to see. Otherwise the tag matches the enclosing class.

An unknown subsystem name in LOG= or a LOG sub=lvl PTY command is rejected (the PTY writes an error line; the config parser emits a startup warning and ignores it).


Configuration reference — LOG=

Syntax:

LOG=<sub>=<lvl>[,<sub>=<lvl>...]
  • Comma-separated <subsystem>=<level> pairs.
  • * sets the default for every subsystem not listed.
  • If LOG= is absent or empty, the default is *=info.
  • Whitespace around = and , is tolerated.

Examples:

# Quiet everything except trunk debug
LOG=*=warn,trunk=debug

# Follow MQTT publishing but keep the rest at info
LOG=mqtt=debug

# Silence the noisy redis subsystem entirely
LOG=redis=off

# Everything at warn — the most common production setting
LOG=*=warn

PTY commands

All commands are sent to /dev/shm/reflector_ctrl (path set by COMMAND_PTY= in [GLOBAL]; the default is already wired up in the stock config). The PTY is half-duplex: write your command, then read from the same file to get the response.

Command Effect
LOG SHOW Write the current <sub>=<lvl> snapshot back to the PTY
LOG <sub>=<lvl> Set one subsystem
LOG <sub1>=<lvl1>,<sub2>=<lvl2> Set several at once, applied left-to-right
LOG *=<lvl> Set the default for every subsystem
LOG RESET Restore the levels read from .conf at startup

LOG RESET does not reread .conf from disk; it reverts in-memory to the snapshot taken when the reflector started.

Reading back the response

echo "LOG SHOW" > /dev/shm/reflector_ctrl
sleep 0.2
cat /dev/shm/reflector_ctrl

Expected output:

trunk=info
satellite=info
twin=info
client=info
mqtt=info
redis=info
core=info

Docker deployments

Logs come out via the Docker json-file driver (10 MB × 3 files by default in the SvxReflectorDashboard compose setup). Read them with:

docker compose logs -f svxreflector

To send a PTY command into a container:

docker compose exec svxreflector sh -c \
  'echo "LOG trunk=debug" > /dev/shm/reflector_ctrl'

The SvxReflectorDashboard web UI under /admin/system_info reads the same Docker log stream via the Docker socket — it does not need any special configuration.


Non-Docker deployments (systemd / file logging)

When the reflector is started with --logfile /var/log/svxreflector.log, the existing LogWriter redirects stdout/stderr to that file and prefixes every line with a timestamp. logrotate integration works unchanged — SIGHUP to the reflector causes LogWriter to reopen the file.

Syslog is also supported: start with --logfile syslog:.


Migrating from TRUNK_DEBUG

TRUNK_DEBUG=1 in [GLOBAL] is obsolete. The replacement is:

LOG=trunk=debug

A startup warning fires if TRUNK_DEBUG is still present in .conf. The new syntax gives strictly more control: you can now silence the rest of the reflector while keeping trunk at debug, which the old boolean flag could not do.


Performance notes

  • Output is asynchronous. Formatting happens on the calling thread, but the actual write() to fd=1 is handed off to a dedicated background worker. The audio path never blocks on a log flush — a stalled log consumer (full pipe, paused logrotate, slow journald) does not stall audio forwarding.
  • Filtered lines cost one atomic load. When a subsystem's level rules a line out, the call site checks one std::atomic<int> and returns without formatting arguments. Debug lines on per-frame paths cost nothing at runtime when the level is warn.
  • The worker never drops a line intentionally. Queue growth is unbounded — if the log consumer stalls (full pipe, paused logrotate), memory grows rather than lines being dropped. A rare short write(2) to a stalled pipe can truncate the tail of one line; the line header is preserved.
  • Argument expressions are still evaluated on every call, even when the subsystem is filtered out — the gate skips formatting, not evaluation. Call sites doing heavy work inside the argument list (an RPC, a large string format) should guard with an explicit geulog::shouldLog(...) check first. Not a concern at current call sites (all pass cheap member accesses).