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
```
This commit is contained in:
Thomas Eizinger 2021-03-29 09:48:56 +11:00
parent c5827f84ca
commit c01cccb288
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96
6 changed files with 3 additions and 22 deletions

3
Cargo.lock generated
View File

@ -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]]

View File

@ -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"] }

View File

@ -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;

View File

@ -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"

View File

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

View File

@ -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")