From 908dae3442baa6f0af5d270e3448780f0856d18a Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 29 Mar 2021 09:54:48 +1100 Subject: [PATCH] Inline tracing initialization This code snippet is so short, it might as well be inlined to give the test more control over what it wants to log. --- monero-harness/tests/monerod.rs | 8 ++++---- monero-harness/tests/testutils/mod.rs | 14 -------------- monero-harness/tests/wallet.rs | 8 ++++---- swap/tests/testutils/mod.rs | 19 ++++--------------- 4 files changed, 12 insertions(+), 37 deletions(-) delete mode 100644 monero-harness/tests/testutils/mod.rs diff --git a/monero-harness/tests/monerod.rs b/monero-harness/tests/monerod.rs index 7e816264..40901b50 100644 --- a/monero-harness/tests/monerod.rs +++ b/monero-harness/tests/monerod.rs @@ -1,15 +1,15 @@ -use crate::testutils::init_tracing; use monero_harness::Monero; use spectral::prelude::*; use std::time::Duration; use testcontainers::clients::Cli; use tokio::time; - -mod testutils; +use tracing_subscriber::util::SubscriberInitExt; #[tokio::test] async fn init_miner_and_mine_to_miner_address() { - let _guard = init_tracing(); + let _guard = tracing_subscriber::fmt() + .with_env_filter("warn,test=debug,monero_harness=debug,monero_rpc=debug") + .set_default(); let tc = Cli::default(); let (monero, _monerod_container) = Monero::new(&tc, vec![]).await.unwrap(); diff --git a/monero-harness/tests/testutils/mod.rs b/monero-harness/tests/testutils/mod.rs deleted file mode 100644 index 4ab21589..00000000 --- a/monero-harness/tests/testutils/mod.rs +++ /dev/null @@ -1,14 +0,0 @@ -use tracing::subscriber::DefaultGuard; - -/// Utility function to initialize logging in the test environment. -/// Note that you have to keep the `_guard` in scope after calling in test: -/// -/// ```rust -/// let _guard = init_tracing(); -/// ``` -pub fn init_tracing() -> DefaultGuard { - use tracing_subscriber::util::SubscriberInitExt as _; - tracing_subscriber::fmt() - .with_env_filter("warn,test=debug,monero_harness=debug,monero_rpc=debug") - .set_default() -} diff --git a/monero-harness/tests/wallet.rs b/monero-harness/tests/wallet.rs index 3314341a..15fb3698 100644 --- a/monero-harness/tests/wallet.rs +++ b/monero-harness/tests/wallet.rs @@ -1,15 +1,15 @@ -use crate::testutils::init_tracing; use monero_harness::{Monero, MoneroWalletRpc}; use spectral::prelude::*; use std::time::Duration; use testcontainers::clients::Cli; use tokio::time::sleep; - -mod testutils; +use tracing_subscriber::util::SubscriberInitExt; #[tokio::test] async fn fund_transfer_and_check_tx_key() { - let _guard = init_tracing(); + let _guard = tracing_subscriber::fmt() + .with_env_filter("warn,test=debug,monero_harness=debug,monero_rpc=debug") + .set_default(); let fund_alice: u64 = 1_000_000_000_000; let fund_bob = 0; diff --git a/swap/tests/testutils/mod.rs b/swap/tests/testutils/mod.rs index 50210abe..16724cff 100644 --- a/swap/tests/testutils/mod.rs +++ b/swap/tests/testutils/mod.rs @@ -28,7 +28,7 @@ use testcontainers::{Container, Docker, RunArgs}; use tokio::sync::mpsc; use tokio::task::JoinHandle; use tokio::time::interval; -use tracing::dispatcher::DefaultGuard; +use tracing_subscriber::util::SubscriberInitExt; use url::Url; use uuid::Uuid; @@ -319,7 +319,9 @@ where { let cli = Cli::default(); - let _guard = init_tracing(); + let _guard = tracing_subscriber::fmt() + .with_env_filter("warn,swap=debug,monero_harness=debug,monero_rpc=info,bitcoin_harness=info,testcontainers=info") + .set_default(); let env_config = C::get_config(); @@ -658,19 +660,6 @@ struct Containers<'a> { electrs: Container<'a, Cli, electrs::Electrs>, } -/// Utility function to initialize logging in the test environment. -/// Note that you have to keep the `_guard` in scope after calling in test: -/// -/// ```rust -/// let _guard = init_tracing(); -/// ``` -pub fn init_tracing() -> DefaultGuard { - use tracing_subscriber::util::SubscriberInitExt as _; - tracing_subscriber::fmt() - .with_env_filter("warn,swap=debug,monero_harness=debug,monero_rpc=info,bitcoin_harness=info,testcontainers=info") - .set_default() -} - pub mod alice_run_until { use swap::protocol::alice::AliceState;