tracing
tracing copied to clipboard
tracing-subscriber: inconsistent behavior between `init` methods
Bug Report
Version
tracing-subscriber v0.3.14
tracing v0.1.35
Platform
x86_64-unknown-linux-gnu
Crates
tracing-subscriber
Description
There appears to be a discrepancy in what the documentation believes is true and what the different format initializers actually do. tracing_subscriber::fmt::init() has documentation saying it is the same as tracing_subscriber::fmt().init(). I think there may be two bugs.
- That code eventually calls
builder.with_max_level(LevelFilter::TRACE)instead of usingDEFAULT_MAX_LEVELwhich is set toINFO. tracing_subscriber::fmt().init()does NOT use env filters andtracing_subscriber::fmt::init()does. This leads to confusing behavior when switching between implementations that are supposed to be the same. NOTE, as far as I can tell this is fixed in main branch.
Example
To reproduce bug 2:
# cargo.toml
[package]
name = "tracing-test"
version = "0.1.0"
edition = "2021"
[dependencies]
tracing-subscriber = "0.3"
tracing = "0.1"
using fmt::init()
fn main() {
tracing_subscriber::fmt::init();
tracing::error!("error");
tracing::warn!("warn");
tracing::info!("info");
tracing::debug!("debug");
tracing::trace!("trace");
}
❯ RUST_LOG=TRACE cargo run --
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/tracing-test`
2022-07-12T17:37:31.613776Z ERROR tracing_test: error
2022-07-12T17:37:31.613807Z WARN tracing_test: warn
2022-07-12T17:37:31.613820Z INFO tracing_test: info
2022-07-12T17:37:31.613832Z DEBUG tracing_test: debug
2022-07-12T17:37:31.613843Z TRACE tracing_test: trace
using fmt().init()
fn main() {
tracing_subscriber::fmt().init();
tracing::error!("error");
tracing::warn!("warn");
tracing::info!("info");
tracing::debug!("debug");
tracing::trace!("trace");
}
❯ RUST_LOG=TRACE cargo run --
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/tracing-test`
2022-07-12T17:38:33.822023Z ERROR tracing_test: error
2022-07-12T17:38:33.822055Z WARN tracing_test: warn
2022-07-12T17:38:33.822067Z INFO tracing_test: info
This issue is a duplicate of #1329, but you're right about the discrepancy. Would you be willing to submit a PR to the v0.1.0 branch fixing the incorrect documentation on tracing_subscriber::fmt().init()?
Is the correct thing to do here to change the comment to reflect that they are not the same or to fix the code so that they are the same?
I can see the argument for changing just the documentation since somebody might already rely on this functionality and 0.2 does not have this problem.
At the moment, we should just change the documentation to reflect reality. The right solution might require a bit more thought.