Expand description
Tracing and logging initialisation.
Why: All binaries need consistent stderr-bound tracing setup; centralising
it prevents duplicated setup across entry points.
What: init_tracing, init_tracing_for_test, DEFAULT_LOG_LEVEL.
Test: logging::tests::*.
Tracing and logging initialisation for tcode.
Why: All tcode binaries and the library’s test harness need consistent
tracing initialisation that writes to stderr (never stdout — stdout is the
API transport channel). Centralising it here prevents duplicated setup and
ensures the try_init pattern is used everywhere so test binaries remain
idempotent.
What: init_tracing initialises the global tracing subscriber from the
RUST_LOG env var. init_tracing_for_test is a lightweight variant for
test binaries that silently drops duplicate init errors.
Test: init_tracing_for_test_is_idempotent calls the function twice and
asserts no panic.
§Log-level convention (#2857)
trusty-code makes control-flow decisions that change a run’s outcome — caps tripping, retries, delegation refusals, fallbacks, truncations, skips, gate interceptions. Every such decision point MUST log at the level below when it fires; the organising principle is:
warn!— the decision silently changes the run’s outcome (a cap trips, a retry budget is exhausted, a gate refuses/intercepts an action, a floor is exceeded). Minimum level for anything that could otherwise only be diagnosed via cross-run forensics (the #2852 class of bug this ticket exists to prevent).info!— a degradation the model or user acts on, but the run proceeds normally (a fallback lane serves results, a redundant re-run is suppressed, a budget truncation drops lowest-scored content, cadence compression fires on schedule).debug!— detail useful for tracing a run’s mechanics but not itself a decision that changes the outcome (byte-level truncation of a single tool’s output, already surfaced in-band to the model).error!— reserved for regression signals: a safeguard fired under conditions where it should have been structurally unreachable (e.g. threshold compaction firing while the cadence compressor is supposed to keep the transcript under budget at all times).
All logs go to stderr via tracing (never stdout — see the module
doc above) and are filtered by RUST_LOG, falling back to info when it
is unset or invalid.
Logs vs. events: structured crate::events are telemetry for the
UI (a typed, machine-consumed fact stream); tracing logs here are for
an operator reading stderr while debugging a run. Both may describe the
same underlying fact, but one must never substitute for the other — an
event emission does not excuse a silent decision point from also logging.
Constants§
- DEFAULT_
LOG_ LEVEL - Log level used when no
RUST_LOGenv var is set.
Functions§
- init_
tracing - Initialise the global tracing subscriber.
- init_
tracing_ for_ test - Initialise the global tracing subscriber, silently ignoring duplicate inits.