-
Notifications
You must be signed in to change notification settings - Fork 752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subscriber/fmt: address UX issues in defaults #1781
Conversation
cac6151
to
0c4c57e
Compare
I removed the one related to #1329 from the changelist:
It looks like fixing #1329 would be harder after all due to the signature complexity, so I'm backing that out for now. |
Thanks for taking the time to work on this! I'm not sure if the approach used here is really the best way to fix these problems, however. Rather than printing a warning when |
Oh, interesting. I'll look into this later. |
Uh oh, looks like this would also be a breaking change because how filters and other things are completely hardcoded into the type parameters:
I wonder if we can change this in a way that leaks less implementation details? Ideally, we would want the default SubscriberBuilder to pick between one of |
You're right that changing the filter to I was thinking that we would do this specifically for the For other functions, which return a builder, it's much more difficult to change them, because of the type signatures. Fortunately, users should only be using these functions if they do need to configure the subscriber differently than the default, so in that case, if we make sure it's very obvious what you get when you call What do you think? |
ping @ishitatsuyuki --- are you still planning on working on this? What do you think of my suggestions from #1781 (comment)? If you don't have the time to make that change, I'm happy to make those additional changes on top of this PR, but I'd like to get this merged at some point soon. |
The previous implementation would fall back to "NOTHING" instead, which was a poor default. Close tokio-rs#735
…is not enabled Close tokio-rs#1697
0c4c57e
to
e61ebff
Compare
Sorry for the review request noise, I had to change the base branch as I implemented your idea directly into the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks like the right approach. I left some style suggestions.
Also, I think rustfmt
needs to be run on this branch to make CI pass.
Once that's all addressed, I'll be very happy to merge this! Thanks!
tracing-subscriber/src/fmt/mod.rs
Outdated
@@ -297,6 +297,8 @@ | |||
//! https://docs.rs/tracing/latest/tracing/trait.Subscriber.html | |||
//! [`tracing`]: https://crates.io/crates/tracing | |||
//! [`fmt::format`]: mod@crate::fmt::format | |||
#[cfg(not(feature = "env-filter"))] | |||
use core::str::FromStr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, take it or leave it: we don't need to import this from core
here, since this whole module requires the std
feature. importing it from core
. this is fine either way, though.
tracing-subscriber/src/fmt/mod.rs
Outdated
Err(std::env::VarError::NotPresent) => {crate::filter::Targets::new()} | ||
Err(e) => { | ||
eprintln!("Ignoring `RUST_LOG`: {:?}", e); | ||
crate::filter::Targets::new() | ||
} | ||
}.with_default(crate::fmt::Subscriber::DEFAULT_MAX_LEVEL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling with_default
on the result of the match will set the default max level in all cases, even if the filter parsed from the env var had a default level. for example, if the user runs a program with RUST_LOG=debug,foo=trace
, where Debug
is the default level, this will overwrite the Debug
default with Info
. instead, I think we should only overwrite the default max level when no filter was parsed from the env var:
Err(std::env::VarError::NotPresent) => {crate::filter::Targets::new()} | |
Err(e) => { | |
eprintln!("Ignoring `RUST_LOG`: {:?}", e); | |
crate::filter::Targets::new() | |
} | |
}.with_default(crate::fmt::Subscriber::DEFAULT_MAX_LEVEL); | |
Err(std::env::VarError::NotPresent) => { | |
crate::filter::Targets::new().with_default(crate::fmt::Subscriber::DEFAULT_MAX_LEVEL) | |
} | |
Err(e) => { | |
eprintln!("Ignoring `RUST_LOG`: {:?}", e); | |
crate::filter::Targets::new().with_default(crate::fmt::Subscriber::DEFAULT_MAX_LEVEL) | |
} | |
}; |
tracing-subscriber/src/fmt/mod.rs
Outdated
#[cfg(not(feature = "env-filter"))] | ||
let targets = match std::env::var("RUST_LOG") { | ||
Ok(var) => { | ||
crate::filter::Targets::from_str(&var).map_err(|e|{eprintln!("Ignoring `RUST_LOG`: {:?}", e);}).unwrap_or_default() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we get an error here, the env variable is set, but it couldn't be parsed successfully. i think it would be nice if the error message also included the value of the env var, so the user can see the whole string that wasn't parsed:
crate::filter::Targets::from_str(&var).map_err(|e|{eprintln!("Ignoring `RUST_LOG`: {:?}", e);}).unwrap_or_default() | |
crate::filter::Targets::from_str(&var).map_err(|e|{eprintln!("Ignoring `RUST_LOG={:?}`: {:?}", var, e);}).unwrap_or_default() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, i think this error implements fmt::Display
, so the message we print might look a little nicer if we used Display
here:
crate::filter::Targets::from_str(&var).map_err(|e|{eprintln!("Ignoring `RUST_LOG`: {:?}", e);}).unwrap_or_default() | |
crate::filter::Targets::from_str(&var).map_err(|e|{eprintln!("Ignoring `RUST_LOG`: {}", e);}).unwrap_or_default() |
Signed-off-by: Eliza Weisman <[email protected]>
Signed-off-by: Eliza Weisman <[email protected]>
# 0.3.5 (Dec 29, 2021) This release re-enables `RUST_LOG` filtering in `tracing_subscriber::fmt`'s default initialization methods, and adds an `OffsetLocalTime` formatter for using local timestamps with the `time` crate. ### Added - **fmt**: Added `OffsetLocalTime` formatter to `fmt::time` for formatting local timestamps with a fixed offset ([#1772]) ### Fixed - **fmt**: Added a `Targets` filter to `fmt::init()` and `fmt::try_init()` when the "env-filter" feature is disabled, so that `RUST_LOG` is still honored ([#1781]) Thanks to @marienz and @ishitatsuyuki for contributing to this release! [#1772]: #1772 [#1781]: #1781
# 0.3.5 (Dec 29, 2021) This release re-enables `RUST_LOG` filtering in `tracing_subscriber::fmt`'s default initialization methods, and adds an `OffsetLocalTime` formatter for using local timestamps with the `time` crate. ### Added - **fmt**: Added `OffsetLocalTime` formatter to `fmt::time` for formatting local timestamps with a fixed offset ([#1772]) ### Fixed - **fmt**: Added a `Targets` filter to `fmt::init()` and `fmt::try_init()` when the "env-filter" feature is disabled, so that `RUST_LOG` is still honored ([#1781]) Thanks to @marienz and @ishitatsuyuki for contributing to this release! [#1772]: #1772 [#1781]: #1781
…t enabled(tokio-rs#1781) The removal of `env-filter` from the default features in 0.3.0 has caused a lot of developer frustration. This PR changes `tracing_subscriber::fmt::init()` and `try_init` to fall back to adding a `Targets` filter parsed from the `RUST_LOG` environment variable, rather than a `LevelFilter` with the default max level. This way, `RUST_LOG`-based filtering will still "just work" out of the box with the default initialization functions, regardless of whether or not `EnvFilter` is enabled. Closes tokio-rs#1697 Co-authored-by: Eliza Weisman <[email protected]>
# 0.3.5 (Dec 29, 2021) This release re-enables `RUST_LOG` filtering in `tracing_subscriber::fmt`'s default initialization methods, and adds an `OffsetLocalTime` formatter for using local timestamps with the `time` crate. ### Added - **fmt**: Added `OffsetLocalTime` formatter to `fmt::time` for formatting local timestamps with a fixed offset ([tokio-rs#1772]) ### Fixed - **fmt**: Added a `Targets` filter to `fmt::init()` and `fmt::try_init()` when the "env-filter" feature is disabled, so that `RUST_LOG` is still honored ([tokio-rs#1781]) Thanks to @marienz and @ishitatsuyuki for contributing to this release! [tokio-rs#1772]: tokio-rs#1772 [tokio-rs#1781]: tokio-rs#1781
The removal of env-filter from the default features in 0.3.0 has caused a lot of developer frustration.
This PR addresses all of the issue I'm aware of, except #1329, in individual commits.
See the commit message for notes on the implementation and the related issues.