From c01cccb28832a325c1ee9ded3cdd8343a1034981 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 29 Mar 2021 09:48:56 +1100 Subject: [PATCH] Use `tracing-log` feature flag instead of manual initialization This also formats `log` events more nicely. Instead of ``` Mar 29 09:46:16.775 INFO log: Found message after comparing 82 lines log.target="testcontainers::core::wait_for_message" log.module_path="testcontainers::core::wait_for_message" log.file="/home/thomas/.cargo/registry/src/github.com-1ecc6299db9ec823/testcontainers-0.12.0/src/core/wait_for_message.rs" log.line=35 ``` We now have ``` Mar 29 09:57:15.860 INFO testcontainers::core::wait_for_message: Found message after comparing 81 lines ``` --- Cargo.lock | 3 +-- monero-harness/Cargo.toml | 3 +-- monero-harness/tests/testutils/mod.rs | 6 ------ swap/Cargo.toml | 3 +-- swap/src/trace.rs | 4 ---- swap/tests/testutils/mod.rs | 6 ------ 6 files changed, 3 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index abb9815d..cdfa1621 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2004,7 +2004,6 @@ dependencies = [ "testcontainers 0.12.0", "tokio", "tracing", - "tracing-log", "tracing-subscriber", ] @@ -3472,7 +3471,6 @@ dependencies = [ "toml", "tracing", "tracing-futures", - "tracing-log", "tracing-subscriber", "url", "uuid", @@ -3862,6 +3860,7 @@ dependencies = [ "thread_local", "tracing", "tracing-core", + "tracing-log", ] [[package]] diff --git a/monero-harness/Cargo.toml b/monero-harness/Cargo.toml index 26df8af3..fa57f1a9 100644 --- a/monero-harness/Cargo.toml +++ b/monero-harness/Cargo.toml @@ -14,5 +14,4 @@ spectral = "0.6" testcontainers = "0.12" tokio = { version = "1", default-features = false, features = ["rt-multi-thread", "time", "macros"] } tracing = "0.1" -tracing-log = "0.1" -tracing-subscriber = { version = "0.2", default-features = false, features = ["fmt", "ansi", "env-filter"] } +tracing-subscriber = { version = "0.2", default-features = false, features = ["fmt", "ansi", "env-filter", "tracing-log"] } diff --git a/monero-harness/tests/testutils/mod.rs b/monero-harness/tests/testutils/mod.rs index 0f4f34f3..2aad364e 100644 --- a/monero-harness/tests/testutils/mod.rs +++ b/monero-harness/tests/testutils/mod.rs @@ -1,5 +1,4 @@ use tracing::subscriber::DefaultGuard; -use tracing_log::LogTracer; /// Utility function to initialize logging in the test environment. /// Note that you have to keep the `_guard` in scope after calling in test: @@ -8,11 +7,6 @@ use tracing_log::LogTracer; /// let _guard = init_tracing(); /// ``` pub fn init_tracing() -> DefaultGuard { - // converts all log records into tracing events - // Note: Make sure to initialize without unwrapping, otherwise this causes - // trouble when running multiple tests. - let _ = LogTracer::init(); - let global_filter = tracing::Level::WARN; let test_filter = tracing::Level::DEBUG; let monero_harness_filter = tracing::Level::DEBUG; diff --git a/swap/Cargo.toml b/swap/Cargo.toml index 9d5a88be..0a4c4167 100644 --- a/swap/Cargo.toml +++ b/swap/Cargo.toml @@ -52,8 +52,7 @@ tokio-util = { version = "0.6", features = ["io"] } toml = "0.5" tracing = { version = "0.1", features = ["attributes"] } tracing-futures = { version = "0.2", features = ["std-future", "futures-03"] } -tracing-log = "0.1" -tracing-subscriber = { version = "0.2", default-features = false, features = ["fmt", "ansi", "env-filter", "chrono"] } +tracing-subscriber = { version = "0.2", default-features = false, features = ["fmt", "ansi", "env-filter", "chrono", "tracing-log"] } url = { version = "2", features = ["serde"] } uuid = { version = "0.8", features = ["serde", "v4"] } void = "1" diff --git a/swap/src/trace.rs b/swap/src/trace.rs index 2c80de97..70728fd6 100644 --- a/swap/src/trace.rs +++ b/swap/src/trace.rs @@ -1,5 +1,4 @@ use anyhow::Result; -use tracing_log::LogTracer; use tracing_subscriber::filter::LevelFilter; use tracing_subscriber::FmtSubscriber; @@ -8,9 +7,6 @@ pub fn init_tracing(level: LevelFilter) -> Result<()> { return Ok(()); } - // We want upstream library log messages, just only at Info level. - LogTracer::init_with_filter(tracing_log::log::LevelFilter::Info)?; - let is_terminal = atty::is(atty::Stream::Stderr); let builder = FmtSubscriber::builder() diff --git a/swap/tests/testutils/mod.rs b/swap/tests/testutils/mod.rs index fb442c2d..50210abe 100644 --- a/swap/tests/testutils/mod.rs +++ b/swap/tests/testutils/mod.rs @@ -29,7 +29,6 @@ use tokio::sync::mpsc; use tokio::task::JoinHandle; use tokio::time::interval; use tracing::dispatcher::DefaultGuard; -use tracing_log::LogTracer; use url::Url; use uuid::Uuid; @@ -666,11 +665,6 @@ struct Containers<'a> { /// let _guard = init_tracing(); /// ``` pub fn init_tracing() -> DefaultGuard { - // converts all log records into tracing events - // Note: Make sure to initialize without unwrapping, otherwise this causes - // trouble when running multiple tests. - let _ = LogTracer::init(); - 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")