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