Skip to content

Commit

Permalink
tracing-subscriber: correct fmt::init() documentation
Browse files Browse the repository at this point in the history
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`.

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 tokio-rs#1329
  • Loading branch information
cgbur committed Jul 16, 2022
1 parent 9c4bd43 commit e0f4bef
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tracing-subscriber/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1188,10 +1188,13 @@ pub fn try_init() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
/// If the `tracing-log` feature is enabled, this will also install
/// the LogTracer to convert `Log` records into `tracing` `Event`s.
///
/// This is shorthand for
/// If the `env-filter` feature is enabled, this is shorthand for
///
/// ```rust
/// tracing_subscriber::fmt().init()
/// # use tracing_subscriber::EnvFilter;
/// tracing_subscriber::fmt()
/// .with_env_filter(EnvFilter::from_default_env())
/// .init();
/// ```
///
/// # Panics
Expand Down

0 comments on commit e0f4bef

Please sign in to comment.