Skip to main content

capture

Function capture 

Source
pub fn capture<R>(f: impl FnOnce() -> R) -> (R, CapturedDiagnostics)
Expand description

Run f on the CURRENT (worker) thread with diagnostic capture. Binds a fresh thread-local log buffer for the duration so any Error!/Warn!/Info! f emits (directly or deep inside a conversion helper) is recorded instead of lost, and snapshots the worker’s REPORT counters afterward. The returned CapturedDiagnostics is replayed on the main thread by replay_captured after the worker is joined, so the messages reach the bound cortex.log and the failures register in status_code.

Assumes the worker thread has no pre-bound buffer (the spawned post-processing pool threads start clean); it does not save/restore a prior binding.

INVARIANTS (unenforced by types; guard the fleet’s canonical signal):

  • one capture per thread lifetime — bind_log() CLOBBERS any pre-bound buffer, and snapshot_report_counts does not reset, so reusing capture on a pooled thread would drop earlier text and double-merge counts;
  • callers must replay_captured the result on the MAIN thread exactly once (a panicking worker never returns, losing its pre-panic capture — the real-time stderr echo retains it, and the caller’s worker_panicked Error keeps status from reading clean).