-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Improve error handling for log filter #13897
Improve error handling for log filter #13897
Conversation
…ed because of a parsing error
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
Agreed, can you open an issue on their repo linking this PR? |
Here is the issue tokio-rs/tracing#3009. Shall I open an issue in this repo to follow on this once this PR is merged? |
Yes please. |
Objective
This PR aims to improve error handling for log filters.
Closes #13850
Solution
I changed the parsing of LogPlugin its filter to lossy, so that it prints the directives with an error but does not skip them. I decided on letting it gracefully handle the error instead of panicking to be consistent with the parsing from an environment variable that it tries to do before parsing it from the LogPlugin filter.
If the user decides to specify the filter by an environment variable, it would silently fail and default to the LogPlugin filter value. It now prints an error before defaulting to the LogPlugin filter value.
Unfortunately, I could not try and loosely set the filter from the environment variable because the
tracing-subscriber
module does not expose the function it uses to get the environment variable, and I would rather not copy its code. We may want to check if the maintainers are open to exposing the method.Testing
Consider the following bevy app, where the second of the 3 filters is invalid:
In the previous situation, it would panic with a non-descriptive error: "called
Result::unwrap()
on anErr
value: ParseError { kind: Other(None) }", while only 1 of the 3 filters is invalid. When runningcargo run
, it will now use the two valid filters and print an error on the invalid filter.This error comes from
tracing-subscriber
and cannot be altered as far as I can see.To test setting the log filter through an environment variable, you can use
RUST_LOG="wgpu=error,my_package=invalid_log_level,naga=warn" cargo run
to run your app. In the previous situation it would silently fail and use the LogPlugin filter. It will now print an error before using the LogPlugin filter.Changelog