- Notifications
You must be signed in to change notification settings - Fork807
Add env-filter-explorer example#3233
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
kaffarell left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Wow, this is very nice! Did not yet look at the code in-depth but noticed one issue: When the envfilter is empty, no event is displayed (this is not correct, every event should be shown). Same on bogus input, e.g., when writing "abc" every event should be visible.
This is the result of calling EnvFilterBuilder::parse(). There's nothing more to it than that. |
hds commentedApr 11, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
EDIT: I think I'm wrong about the implementation of this (but right about the docs), that should probably be fixed. @kaffarell It depends on the default directive, if none is given then (This is different from if 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.
This looks awesome! If we could avoid reformatting unrelated lines in Cargo.toml that would be good though.
examples/Cargo.toml Outdated
tracing-futures = { version = "0.3", path = "../tracing-futures", features = ["futures-01"] } | ||
tracing-attributes = { path = "../tracing-attributes", version = "0.2"} | ||
tracing-log = { path = "../tracing-log", version = "0.2", features = ["env_logger"] } | ||
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3", features = [ |
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.
It would be good if we could avoid reformatting. I think this isn't "standard" TOML formatting, it comes from a specific extension.
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.
Yeah I usehttps://marketplace.visualstudio.com/items?itemName=tamasfe.even-better-toml in most projects and often forget to turn it off when viewing other projects. Apologies.
I removed the wrapping changes, but left the spacing changes as they are consistent with the rest of the file. I hope that's ok. If not I can remove those too.
OK, I wrote a test for the case as per the documentation, and it fails: #[test]fnempty_string(){let filter:EnvFilter ="".parse().expect("filter should parse");let(collector, finished) = collector::mock().event(expect::event().at_level(Level::ERROR)).only().run_with_handle();let subscriber = collector.with(filter);with_default(subscriber, ||{ tracing::trace!("this should be disabled"); tracing::debug!("this should be disabled"); tracing::info!("this should be disabled"); tracing::warn!("this should be disabled"); tracing::error!("this shouldn't be disabled");}); finished.assert_finished();} But it fails because nothing is received by the collector, it's interpreting an empty string as |
Intuitively (to me at least), empty should effectively be a noop, which for a filter probably means just default. That said, I have a vague recollection there's a bit of weirdness where if the envfilter feature is not enabled you get info level logs by default, but it changes to error level if enabled. That also seems a bit counterintuitive. (I may be misremembering and I'm not near my computer for a few days to check) |
kaffarell commentedApr 11, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Oh you're right, my bad, I tested with This behavior is kind weird though. We set a default_directive (with min level ERROR) on the |
This example demonstrates how to use the `tracing-subscriber` crate's`EnvFilter` type to filter log messages based on their metadata. Theexample provides a text area where users can input an environment filterstring, and displays the log messages that would be captured by thatfilter.
joshka commentedMay 14, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Rebased, removed the inferno dep bump, fixed the manifest formatting. |
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.
This looks great. Thank you!
906f00c
intotokio-rs:masterUh oh!
There was an error while loading.Please reload this page.
This example demonstrates how to use the `tracing-subscriber` crate's`EnvFilter` type to filter log messages based on their metadata. Theexample provides a text area where users can input an environment filterstring, and displays the log messages that would be captured by thatfilter.
This example demonstrates how to use the `tracing-subscriber` crate's`EnvFilter` type to filter log messages based on their metadata. Theexample provides a text area where users can input an environment filterstring, and displays the log messages that would be captured by thatfilter.
Motivation
Ondiscord, Conrad suggested a website to experiment with env-filter syntax. I think a TUI in tree makes a pretty decent replacement, especially as the output can exactly match the output that a real user might see if they're configuring tracing_subscriber with the default values.
Solution
This example demonstrates how to use the
tracing-subscriber
crate'sEnvFilter
type to filter log messages based on their metadata. Theexample provides a text area where users can input an environment filter
string, and displays the log messages that would be captured by that
filter.
There are preset filters that can be selected that show off the syntax.