Function rustwide::logging::capture [−][src]
pub fn capture<R>(storage: &LogStorage, f: impl FnOnce() -> R) -> R
Capture all log messages emitted inside a closure.
This function will capture all the message the provided closure emitted in the current
thread, forwarding them to the provided LogStorage
. rustwide’s logging system needs to be
initialized before calling this function (either with init
or init_with
).
Example
use log::{info, debug, LevelFilter}; use rustwide::logging::{self, LogStorage}; let storage = LogStorage::new(LevelFilter::Info); logging::capture(&storage, || { info!("foo"); debug!("bar"); }); assert_eq!("[INFO] foo\n", storage.to_string());