tracing icon indicating copy to clipboard operation
tracing copied to clipboard

Add `EnvFilter::from_directives`

Open Plebshot opened this issue 1 year 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