From 1a2857af2901ea63a9eafccb49c00f46c01e32da Mon Sep 17 00:00:00 2001 From: Daniel Karzel Date: Wed, 9 Dec 2020 11:48:53 +1100 Subject: [PATCH] Properly init tracing per test and reverse the filter to be exclusive Tracing should be initialized by test and the `_guard` kept alive within the test. Re-using this code in different tests does not really have any additional value. Instead of specifying what messages we want to include, I went for a filter that excludes noise. That way we get more useful logging. --- swap/tests/e2e.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/swap/tests/e2e.rs b/swap/tests/e2e.rs index 352aa8f4..a7f8fd17 100644 --- a/swap/tests/e2e.rs +++ b/swap/tests/e2e.rs @@ -12,12 +12,16 @@ use tempfile::tempdir; use testcontainers::clients::Cli; use uuid::Uuid; use xmr_btc::{bitcoin, config::Config, cross_curve_dleq}; +use tracing_subscriber::util::SubscriberInitExt as _; /// Run the following tests with RUST_MIN_STACK=10000000 #[tokio::test] async fn happy_path() { - init_tracing(); + let _guard = tracing_subscriber::fmt() + .with_env_filter("trace,hyper=warn") + .set_default(); + let cli = Cli::default(); let bitcoind = Bitcoind::new(&cli, "0.19.1").unwrap(); let _ = bitcoind.init(5).await; @@ -105,7 +109,11 @@ async fn happy_path() { /// the encsig and fail to refund or redeem. Alice punishes. #[tokio::test] async fn alice_punishes_if_bob_never_acts_after_fund() { - init_tracing(); + + let _guard = tracing_subscriber::fmt() + .with_env_filter("trace,hyper=warn") + .set_default(); + let cli = Cli::default(); let bitcoind = Bitcoind::new(&cli, "0.19.1").unwrap(); let _ = bitcoind.init(5).await; @@ -306,11 +314,3 @@ async fn init_bob( (bob_state, bob_swarm, bob_btc_wallet, bob_xmr_wallet, bob_db) } - -fn init_tracing() { - use tracing_subscriber::util::SubscriberInitExt as _; - let _guard = tracing_subscriber::fmt() - .with_env_filter("swap=info,xmr_btc=info") - .with_ansi(false) - .set_default(); -}