Skip to main content

Module logging

Module logging 

Source
Expand description

Process-wide logging: the subscriber main installs, with a reloadable slot for the OTLP log-export layer.

The subscriber must exist before any subcommand logs, but the [observability] config that decides whether daemon logs also export over OTLP is only read later (by the daemon, after Config::load). Bridging that gap is what the reload slot is for: init installs the fmt layer plus an empty slot and parks the reload handle in a static; install_otel_layer fills the slot once the daemon has built its exporter. Everything stays on stderr - lev agent-client uses stdout as its JSON-RPC channel, and a stray log line there would corrupt the stream a host is parsing.

stderr is not safe either while a full-screen TUI is up, which is what hold_for_tui exists for. lev setup and lev dash own the alternate screen on stdout, but stderr is the same terminal, so a log line lands inside the frame. Raw mode makes it worse than untidy: OPOST is off, so the newline is a bare line feed with no carriage return and each line starts where the last one ended, staircasing across the screen. And ratatui only redraws cells it believes changed, so nothing ever paints over the mess. A verification call at debug was enough to fill the wizard with what looked like garbage.

So while a TUI holds the terminal, log lines are buffered instead of written, and flushed to stderr when it lets go. Nothing is lost, and nothing lands on the screen while somebody is looking at it.

Functions§

hold_for_tui
Park log output for as long as a TUI owns the terminal.
init
Install the process-wide subscriber: fmt → stderr at info (debug when verbose), plus the empty reloadable OTLP slot.
install_otel_layer
Fill the reload slot with the daemon’s OTLP log-export layer. Returns whether the layer was installed - false when init hasn’t run (a library consumer with its own subscriber) or the slot is gone.
release_from_tui
Hand the terminal back and flush whatever was logged meanwhile.