use std::sync::{Mutex, OnceLock};
struct CaptureLog;
static RECORDS: Mutex<Vec<String>> = Mutex::new(Vec::new());
static INSTALLED: OnceLock<()> = OnceLock::new();
impl log::Log for CaptureLog {
fn enabled(&self, _: &log::Metadata<'_>) -> bool {
true
}
fn log(&self, record: &log::Record<'_>) {
RECORDS.lock().unwrap().push(record.args().to_string());
}
fn flush(&self) {}
}
pub(crate) fn install() {
INSTALLED.get_or_init(|| {
log::set_logger(&CaptureLog).expect("first logger in this test process");
log::set_max_level(log::LevelFilter::Trace);
});
}
pub(crate) fn mark() -> usize {
RECORDS.lock().unwrap().len()
}
pub(crate) fn contains_since(mark: usize, marker: &str) -> bool {
RECORDS.lock().unwrap()[mark..].iter().any(|m| m.contains(marker))
}
#[cfg(test)]
#[path = "log_capture_tests.rs"]
mod log_capture_tests;