Skip to main content

assert_logged

Function assert_logged 

Source
pub fn assert_logged(expected_message: &str)
Expand description

Asserts that the message has been logged and removes it from the log of this thread.

§Panics

Will panic if the message does not appear in the log.

§Example

log::error!("Something went wrong");
log::info!("Something happened");
log::error!("Something went wrong");

// This will not panic as the message was logged
assert_logged("Something went wrong");

// This will not panic as the message was logged
assert_logged("Something happened");

// This will not panic as the first call removed only the first matching log message
assert_logged("Something went wrong");

// This will panic as all matching log messages have been removed
assert_logged("Something went wrong");