-
Notifications
You must be signed in to change notification settings - Fork 683
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
Add EnvFilter::from_directives
#2763
base: master
Are you sure you want to change the base?
Conversation
Thank you! I’m happy to see a PR to make such an API public. For what it’s worth, I was looking for it, but ended up parsing strings instead. |
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 seems worth having, thank you!
Are there any blockers to getting this merged besides the branch being out-of-date? Just bumped into this, I can make an updated the PR if the sentiment hasn't changed and @Plebshot doesn't mind |
No blockers, it only awaits review as far as I know. I just synced the fork to be up to date though. Thanks for the reminder. |
/// # Ok(()) } | ||
/// ``` | ||
pub fn from_directives(dirs: impl IntoIterator<Item = Directive>) -> Self { | ||
Self::builder().from_directives(dirs) |
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.
Should Builder::from_directives
be part of public API as well?
Motivation
I was using an
EnvFilter
within atracing_subscriber::reload
layer, to be able to change the filter at runtime via a config file.Here, I let the deserialization take care of validating the correctness of the configured filter directives.
However, there wasn't a straightforward way to construct the
EnvFilter
via already parsed directives.Solution
There is a private
from_directives
method on theBuilder
, which was already considered by @hawkw to be made public.Instead, I opted to creating a new, similar method directly on the
EnvFilter
.This should be easier to discover and more convenient than having to call
EnvFilter::builder().from_directives()
.Though, we could consider making both variants public.
This is my first contribution to tokio, so let me know if something is missing from the PR!