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§
- Extend
Guard - A guard objects which restores MDC entries when dropped.
- Insert
Guard - A guard object which restores an MDC entry when dropped.
Functions§
- clear
- Removes all values from the MDC.
- extend
- Extends the MDC with new entries.
- extend_
scoped - Extends the MDC with new entries in a scoped fashion.
- get
- Retrieves a value from the MDC.
- insert
- Inserts a new entry into the MDC, returning the old value.
- insert_
scoped - Inserts a new entry into the MDC in a scoped fashion.
- iter
- Invokes the provided closure for each entry in the MDC.
- remove
- Removes a value from the MDC.