7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 1 | /// Initialize a tracing subscriber if the target architecture is not WASM. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 2 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 3 | /// Uses a sensible default filter that can be overridden through the `RUST_LOG` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 4 | /// environment variable and runs once before all tests by using the [`ctor`] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 5 | /// crate. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 6 | /// |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 7 | /// Invoke this macro once per compilation unit (`lib.rs`, `tests/*.rs`, |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 8 | /// `tests/*/main.rs`). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 9 | #[macro_export] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 10 | macro_rules! init_tracing_for_tests { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 11 | () => { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 12 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 13 | #[$crate::__macro_support::ctor] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 14 | fn init_logging() { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 15 | use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 16 | use $crate::__macro_support::tracing_subscriber; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 17 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 18 | tracing_subscriber::registry() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 19 | .with(tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 20 | // Output is only printed for failing tests, but still we shouldn't overload |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 21 | // the output with unnecessary info. When debugging a specific test, it's easy |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 22 | // to override this default by setting the `RUST_LOG` environment variable. |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 23 | // |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 24 | // Since tracing_subscriber does prefix matching, the `matrix_sdk=` directive |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 25 | // takes effect for all the main crates (`matrix_sdk_base`, `matrix_sdk_crypto` |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 26 | // and so on). |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 27 | "info,matrix_sdk=debug".into() |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 28 | })) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 29 | .with(tracing_subscriber::fmt::layer().with_test_writer()) |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 30 | .init(); |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 31 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 32 | }; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 33 | } |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 34 | |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 35 | #[doc(hidden)] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 36 | pub mod __macro_support { |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 37 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 38 | pub use ctor::ctor; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 39 | #[cfg(not(target_family = "wasm"))] |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 40 | pub use tracing_subscriber; |
7ff8adafe9e4 | atagen | 2026-10-22 12:30 UTC | 41 | } |