tracing icon indicating copy to clipboard operation
tracing copied to clipboard

`EnvFilter` could implement `Clone`

Open jamesmunns opened this issue 1 year ago • 4 comments

Feature Request

Crates

tracing-subscriber

Motivation

As of clap v4, there is now a Clone requirement on some part of the parse machinery. This means that trying to take/parse an EnvFilter does not work, as it does not fulfill the Clone bound

Proposal

Add the Clone bound to EnvFilter, or provide a type that does, which can be used with Clap.

Alternatives

Provide some other documented way of taking tracing Filter directives from Clap and other similar tools

jamesmunns avatar Oct 29 '22 12:10 jamesmunns

If it's useful, I could provide a minimal repro of a small project that takes trace level directives from a CLI.

I have a version written by Eliza that works with clap v3 in my melpomene project, though there have been some changes to the derive proc macro format in v4.

jamesmunns avatar Oct 29 '22 12:10 jamesmunns

Also, if this is as simple as "okay add Clone to the derive list", I can open a PR that does this! I just wasn't sure if this was intentional or there would be some compelling or complicated reason not to do this.

jamesmunns avatar Oct 29 '22 12:10 jamesmunns

I'm trying to remember if we can add Clone to the derive list, but I recall that adding Layer implementations for Arc<dyn Layer> broke per-layer filtering. I don't recall if this would also apply to EnvFilter—it might, it's kinda a hairy implementation—but I'd try adding Clone to it and using in per-layer Filters and seeing if things go screwy.

davidbarsky avatar Nov 02 '22 17:11 davidbarsky

Clone would also be useful in cases where you're using layer.with_filter(env_filter) on multiple layers. In my case, I'm trying to combine tokio-console (which needs an unfiltered layer) with several logging-related layers that need the same filter.

It looks like there was a PR for this open a while ago (#2398), but it was closed by the author. I'm good to pick it up again, if it's likely to be accepted.

Benjamin-L avatar Apr 25 '24 17:04 Benjamin-L