-
Notifications
You must be signed in to change notification settings - Fork 717
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
EnvFilter overwrites all attempts to set a default value #1466
Comments
Here's the ugly workaround: const DEFAULT_LEVEL: tracing::Level = tracing::Level::INFO;
let input = std::env::var("RUST_LOG").expect("fixme");
let mut directives = DEFAULT_LEVEL.to_string();
if !input.is_empty() {
directives.push(',');
directives.push_str(&input);
}
let filter = tracing_subscriber::EnvFilter::try_new(directives).expect("fixme");
tracing_subscriber::fmt()
.with_env_filter(filter)
.init(); |
Adapted workaround from tokio-rs/tracing#1466
Adapted workaround from tokio-rs/tracing#1466
A feature that solves this would be quite useful. We have a similar workaround: https://gitlab.com/veloren/veloren/-/blob/cba946c07b5ec42fb5c47b1c59f5bc8def40e837/common/frontend/src/lib.rs#L87 |
This is already supported, just needs to be better documented. tracing_subscriber::fmt()
.with_env_filter(
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info")),
)
.init(); |
@vilgotf I'm looking back over this and I think it doesn't address my specific use case of having several directives that are applied before the ones from |
Thinking about this further, I think it could be convenient to have a method to parse and apply directives from an env var to an existing Another idea that came to mind is an |
2321: Workaround to prevent overwriting RUST_LOG r=klochowicz a=bonomat So far we overwrote RUST_LOG log settings using . This is annoying because hardcoded log levels can't be changed later on. With this workaround we can have smart defaults but allow the user to overwrite the log level using RUST_LOG // edit// unfortunately tracing does not allow us to do this differently. There is an open ticket which inspired this solution: tokio-rs/tracing#1466 Co-authored-by: Philipp Hoenisch <philipp@hoenisch.at>
Bug Report
Version
Platform
Linux 5.4.109 x86_64
Description
EnvFilter
has no way of setting defaults..add_directive
is wrong (and the examples lead to bad behavior) because it overrides$RUST_LOG
, as it is added to the end of whatever the user specified, overriding e.g.RUST_LOG=trace
.SubscriberBuilder::with_max_level
is wrong because.with_env_filter
explicit overwrites that, as per documentation.EnvFilter
internally defaults toERROR
(not documented anywhere).There is no clean way to achieve
RUST_LOG=warn
This is related to #1400 but I don't think the fallback value necessarily solves the problem (consider desired application default level INFO and
RUST_LOG=some_crate::error
) and I don't want the problem be marked closed because a proposed solution is rejected.The text was updated successfully, but these errors were encountered: