Skip to main content

Module logging

Module logging 

Source
Expand description

Tracing writer that suppresses output while the TUI is active.

§Why this exists

main.rs initialises its tracing-subscriber before the TUI takes over the terminal. After the TUI enters its alternate screen, every tracing::info! / tracing::warn! is still being written to the stderr file descriptor — which is the same descriptor the alternate screen is rendered onto, so the log lines land inside the TUI surface (typically right next to the input box, since that’s where the cursor was last parked by terminal.draw). The user sees stray log lines like 2026-06-03T… INFO agent.turn: finished steps=2 … rendered inside their input box.

§How it works

The TUI_QUIET atomic flag flips to true while the TUI is running. The StderrOrNull writer short-circuits to a no-op while the flag is set, and falls back to std::io::stderr otherwise. The TUI’s run() function takes an RAII guard via suppress_tracing_for_tui so the flag is restored on every exit path — including panics — letting the user still see the panic message on stderr after LeaveAlternateScreen.

§What about user-visible logs during a TUI session?

Things the user actually wants to see during a session (hook progress, the spinner verb, etc.) flow through the TUI’s own event sink, not the global subscriber. If you need a brand-new tracing::info! line to be visible during a TUI session, push it onto the sink as a UiEvent instead.

Structs§

StderrOrNull
io::Write adapter that drops every byte while the TUI is active and otherwise mirrors std::io::stderr.
StderrOrNullMaker
MakeWriter factory that hands out StderrOrNull writers. The tracing_subscriber::fmt layer accepts this in with_writer.
TuiQuietGuard
RAII guard that flips [set_tui_quiet(false)] on drop, ensuring the global tracing writer is restored even if the TUI panics partway through.

Functions§

is_tui_quiet
Returns the current TUI-quiet state. Exposed for tests.
set_tui_quiet
Mark the global tracing writer as suppressed (TUI active) or normal. Called by tui::run() via the RAII guard below; exposed publicly in case other long-running surfaces (e.g. an HTTP server’s interactive console) want the same behaviour.
suppress_tracing_for_tui
Acquire a guard that holds the tracing writer in the suppressed state. When the guard is dropped the writer is restored. Use this at the very top of tui::run() (before enable_raw_mode).