Expand description
A mapped diagnostic context (MDC) for use with the log
crate.
An MDC is a thread local map of strings used to make relevant information from a system available in its log messages. Logging crates such as log4rs will retrieve values from the MDC for output.
For example, a web server may process many requests simultaneously on different threads. Generating an ID for each request and storing it in the MDC makes it easy to partition log messages on a per-request basis.
Examples
Forwarding the contents of the MDC to a new thread:
use std::thread;
let mut mdc = vec![];
log_mdc::iter(|k, v| mdc.push((k.to_owned(), v.to_owned())));
thread::spawn(|| {
log_mdc::extend(mdc);
});
Structs
- A guard objects which restores MDC entries when dropped.
- A guard object which restores an MDC entry when dropped.
Functions
- Removes all values from the MDC.
- Extends the MDC with new entries.
- Extends the MDC with new entries in a scoped fashion.
- Retrieves a value from the MDC.
- Inserts a new entry into the MDC, returning the old value.
- Inserts a new entry into the MDC in a scoped fashion.
- Invokes the provided closure for each entry in the MDC.
- Removes a value from the MDC.