Available on crate feature
std only.Expand description
Thread-local logging context.
Context carries ambient key-value data that gets attached to every
record emitted from the current thread. Typical use: stash a
trace_id / request_id at the entry of a request handler so all
downstream log lines correlate. The ContextGuard returned by
with_field (and friends) removes the value when dropped.
Context is intentionally thread-scoped. For async task propagation, capture context fields at task spawn and re-install them on the task’s executor thread; this crate does not depend on a specific async runtime.
Structs§
- Context
Guard - RAII guard that removes a context slot when dropped.
Constants§
- MAX_
CONTEXT_ SLOTS - Maximum number of context slots per thread. Fixed-size so the snapshot path is allocation-free.
Functions§
- clear
- Remove all context entries on the current thread.
- len
- Number of context entries on the current thread.
- with_
field - Push a key/value pair onto the current thread’s context.
- with_
request_ id - Convenience: push a
request_idfield. - with_
snapshot - Run
fwith the current thread’s context exposed as a borrowed slice ofField. No allocation: the slice is filled from a stack-resident buffer. - with_
trace_ id - Convenience: push a
trace_idfield.