Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

Plebshot
Copy link

Motivation

I was using an EnvFilter within a tracing_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 the Builder, 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!

@Plebshot Plebshot requested review from hawkw, davidbarsky and a team as code owners October 17, 2023 22:07
@CBenoit
Copy link
Sponsor Contributor

CBenoit commented Oct 19, 2023

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.

Copy link
Member

@hawkw hawkw left a 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!

@DCNick3
Copy link

DCNick3 commented Jul 11, 2024

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

@Plebshot
Copy link
Author

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)
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants