relay_log/
test.rs

1use tracing_subscriber::EnvFilter;
2
3// Import CRATE_NAMES, which lists all crates in the workspace.
4include!(concat!(env!("OUT_DIR"), "/constants.gen.rs"));
5
6#[doc(hidden)]
7pub fn __init_test() {
8    let mut env_filter = EnvFilter::new("ERROR");
9
10    // Add all internal modules with maximum log-level.
11    for name in CRATE_NAMES {
12        env_filter = env_filter.add_directive(format!("{name}=TRACE").parse().unwrap());
13    }
14
15    tracing_subscriber::fmt::fmt()
16        .with_env_filter(env_filter)
17        .with_target(true)
18        .with_test_writer()
19        .compact()
20        .try_init()
21        .ok();
22}
23
24/// Initialize the logger for testing.
25///
26/// This logs to the stdout registered by the Rust test runner, and only captures logs from the
27/// calling crate.
28///
29/// # Example
30///
31/// ```
32/// relay_log::init_test!();
33/// ```
34#[macro_export]
35macro_rules! init_test {
36    () => {
37        $crate::__init_test();
38    };
39}