Skip to content

Commit

Permalink
subscriber: Warn if RUST_LOG is set and env-filter is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
ishitatsuyuki committed Dec 16, 2021
1 parent 5fbf215 commit 0c4c57e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tracing-subscriber/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,22 @@ where
/// because a global collector was already installed by another
/// call to `try_init`.
pub fn try_init(self) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
#[cfg(all(not(feature = "env-filter"), feature = "std"))]
{
// This should refer to EnvFilter::DEFAULT_ENV, but it is unavailable when the
// "env-filter" feature is disabled, so we just hardcode it here
if std::env::var_os("RUST_LOG").is_some() {
eprint!("\
tracing-subscriber: Ignoring `RUST_LOG` as the `env-filter` feature is not enabled.
To fix this, replaces the corresponding line with the following in your \
Cargo.toml:
tracing-subscriber = {{ version = \"{}\", features = [\"env-filter\"] }}
",
env!("CARGO_PKG_VERSION"));
}
}

use crate::util::SubscriberInitExt;
self.finish().try_init()?;

Expand Down

0 comments on commit 0c4c57e

Please sign in to comment.