let libtest capture logs

This commit is contained in:
Scott Lamb 2023-08-08 18:24:50 -07:00
parent faba358925
commit 2a8c1bb632
2 changed files with 17 additions and 1 deletions

View File

@ -154,3 +154,19 @@ pub fn install() {
std::panic::set_hook(Box::new(&panic_hook));
}
}
pub fn install_for_tests() {
let filter = tracing_subscriber::EnvFilter::builder()
.with_default_directive(tracing_subscriber::filter::LevelFilter::INFO.into())
.with_env_var("MOONFIRE_LOG")
.from_env_lossy();
tracing_log::LogTracer::init().unwrap();
let sub = tracing_subscriber::registry().with(
tracing_subscriber::fmt::Layer::new()
.with_test_writer()
.with_timer(ChronoTimer)
.with_thread_names(true)
.with_filter(filter),
);
tracing::subscriber::set_global_default(sub).unwrap();
}

View File

@ -38,7 +38,7 @@ pub const TEST_VIDEO_SAMPLE_ENTRY_DATA: &[u8] =
/// * use a fast but insecure password hashing format.
pub fn init() {
INIT.call_once(|| {
base::tracing_setup::install();
base::tracing_setup::install_for_tests();
env::set_var("TZ", "America/Los_Angeles");
time::tzset();
crate::auth::set_test_config();