tracing icon indicating copy to clipboard operation
tracing copied to clipboard

Add `EnvFilter::from_directives`

Open Plebshot opened this issue 2 years ago • 3 comments

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 avatar Oct 17 '23 22:10 Plebshot

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.

CBenoit avatar Oct 19 '23 00:10 CBenoit

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

DCNick3 avatar Jul 11 '24 15:07 DCNick3

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.

Plebshot avatar Jul 11 '24 22:07 Plebshot