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.
This commit is contained in:
Thomas Eizinger 2021-03-29 09:54:48 +11:00
parent 96c87bca71
commit 908dae3442
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
4 changed files with 12 additions and 37 deletions

View File

@ -1,15 +1,15 @@
use crate::testutils::init_tracing;
use monero_harness::Monero; use monero_harness::Monero;
use spectral::prelude::*; use spectral::prelude::*;
use std::time::Duration; use std::time::Duration;
use testcontainers::clients::Cli; use testcontainers::clients::Cli;
use tokio::time; use tokio::time;
use tracing_subscriber::util::SubscriberInitExt;
mod testutils;
#[tokio::test] #[tokio::test]
async fn init_miner_and_mine_to_miner_address() { 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 tc = Cli::default();
let (monero, _monerod_container) = Monero::new(&tc, vec![]).await.unwrap(); let (monero, _monerod_container) = Monero::new(&tc, vec![]).await.unwrap();

View File

@ -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()
}

View File

@ -1,15 +1,15 @@
use crate::testutils::init_tracing;
use monero_harness::{Monero, MoneroWalletRpc}; use monero_harness::{Monero, MoneroWalletRpc};
use spectral::prelude::*; use spectral::prelude::*;
use std::time::Duration; use std::time::Duration;
use testcontainers::clients::Cli; use testcontainers::clients::Cli;
use tokio::time::sleep; use tokio::time::sleep;
use tracing_subscriber::util::SubscriberInitExt;
mod testutils;
#[tokio::test] #[tokio::test]
async fn fund_transfer_and_check_tx_key() { 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_alice: u64 = 1_000_000_000_000;
let fund_bob = 0; let fund_bob = 0;

View File

@ -28,7 +28,7 @@ use testcontainers::{Container, Docker, RunArgs};
use tokio::sync::mpsc; use tokio::sync::mpsc;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
use tokio::time::interval; use tokio::time::interval;
use tracing::dispatcher::DefaultGuard; use tracing_subscriber::util::SubscriberInitExt;
use url::Url; use url::Url;
use uuid::Uuid; use uuid::Uuid;
@ -319,7 +319,9 @@ where
{ {
let cli = Cli::default(); 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(); let env_config = C::get_config();
@ -658,19 +660,6 @@ struct Containers<'a> {
electrs: Container<'a, Cli, electrs::Electrs>, 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 { pub mod alice_run_until {
use swap::protocol::alice::AliceState; use swap::protocol::alice::AliceState;