Demonstrating the inconsistent, confusing behavior of tracing_subscriber
default init
methods.
For all methods, compare what is output by the following, given different init
conditions:
tracing::debug!("debug message!");
tracing::info!("info message!");
tracing::error!("error message!");
-
Initialize with
tracing_subscriber::fmt::init()
:$ cargo run --features init-function 2025-06-30T19:54:28.027555Z INFO binary_crate: info message! 2025-06-30T19:54:28.027675Z ERROR binary_crate: error message! $ RUST_LOG=debug cargo run --features init-function 2025-06-30T19:54:33.248545Z DEBUG binary_crate: debug message! 2025-06-30T19:54:33.248623Z INFO binary_crate: info message! 2025-06-30T19:54:33.248637Z ERROR binary_crate: error message!
Great! That's exactly what I expected. Default to
info
, override withRUST_LOG
. -
Initialize with
tracing_subscriber::fmt().init()
:$ cargo run --features init-method 2025-06-30T19:55:12.333057Z INFO binary_crate: info message! 2025-06-30T19:55:12.333123Z ERROR binary_crate: error message! $ RUST_LOG=debug cargo run --features init-method 2025-06-30T19:55:18.745709Z INFO binary_crate: info message! 2025-06-30T19:55:18.745823Z ERROR binary_crate: error message!
It does not obey
RUST_LOG
!. I have hit this footgun multiple times, and I know of many services I've deployed that aren't going to listen toRUST_LOG
as a result. -
Initialize with
tracing_subscriber::fmt::init()
, but with a transient dependency on theenv-filter
feature:$ cargo run --features init-function,transient-env-filter 2025-06-30T19:57:07.640891Z ERROR binary_crate: error message! $ RUST_LOG=debug cargo run --features init-function,transient-env-filter 2025-06-30T19:57:14.889001Z DEBUG binary_crate: debug message! 2025-06-30T19:57:14.889113Z INFO binary_crate: info message! 2025-06-30T19:57:14.889121Z ERROR binary_crate: error message!
What?! All the sudden the same exact code from #1, which worked as expected, suddenly stops working by adding an unrelated dependency. We add the
lib-crate
dependency, which has 0 lines of code, but simply because it also depends ontracing-subscriber
and theenv-filter
flag our logging breaks.