Skip to content

Commit 41a3524

Browse files
cgburhawkw
authored andcommitted
subscriber: correct fmt::init() documentation (tokio-rs#2224)
## Motivation Previously the documentation for `fmt::init()` was misleading. It stated that it was shorthand for `fmt().init()`. This lead to confusion as users would expect the same behavior from both. However `fmt::init()` would, whether you used the env-filter feature or not, rely on RUST_LOG to set the tracing level. `fmt().init()` does not do this and it must be set with a specific configuration via `with_env_filter`. ## Solution The documentation has been updated to no longer state that it is 1:1 shorthand for the other. The documentation now specifically points out that you must be using the `env-filter` feature and gives a correct example to mimic the `fmt::init()` behavior using `fmt().init()`. Fixes tokio-rs#2217 Fixes tokio-rs#1329 Co-authored-by: Eliza Weisman <eliza@buoyant.io>
1 parent 7253241 commit 41a3524

File tree

1 file changed

+8
-2
lines changed
  • tracing-subscriber/src/fmt

1 file changed

+8
-2
lines changed

tracing-subscriber/src/fmt/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,13 +1239,19 @@ pub fn try_init() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
12391239
/// Install a global tracing collector that listens for events and
12401240
/// filters based on the value of the [`RUST_LOG` environment variable].
12411241
///
1242+
/// The configuration of the subscriber initialized by this function
1243+
/// depends on what [feature flags](crate#feature-flags) are enabled.
1244+
///
12421245
/// If the `tracing-log` feature is enabled, this will also install
12431246
/// the LogTracer to convert `Log` records into `tracing` `Event`s.
12441247
///
1245-
/// This is shorthand for
1248+
/// If the `env-filter` feature is enabled, this is shorthand for
12461249
///
12471250
/// ```rust
1248-
/// tracing_subscriber::fmt().init()
1251+
/// # use tracing_subscriber::EnvFilter;
1252+
/// tracing_subscriber::fmt()
1253+
/// .with_env_filter(EnvFilter::from_default_env())
1254+
/// .init();
12491255
/// ```
12501256
///
12511257
/// # Panics

0 commit comments

Comments
 (0)