Open colinmarc opened 5 months ago
I just discovered that Option<Layer>
implements Layer
, which makes this problem a lot easier. I'm not sure how I missed that in the docs, but maybe one of the fmt
examples should demonstrate that?
You may also use boxed
layers for type erasure: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/trait.FilterExt.html#method.boxed
The complex types on
tracing-subscriber
Subscriber
s andLayer
s make them a little bit difficult to work with. Consider the following example, which switches on a command line flag to write a trace log to a directory:This fails to compile with:
I'm relatively new to rust, so it could be I'm missing something obvious, but it seems like the type system prevents any conditional logic when setting up logging, which I would expect to be the norm for complicated apps. An imperative
fn register(&mut self, impl Layer)
would probably fix that case, but there's another problem, which is that the type system aroundSubscriber
s is fairly illegible at the moment.Here's an actual screenshot of my terminal from last night when I was looking for workarounds to this problem:
I understand that there are complex requirements here, which in turn necessitate lots of API surface. And I don't have any concrete suggestions to make beyond what I mentioned earlier, so I hope this criticism isn't unwelcome. If someone is willing to point me in the right direction, I'm more than happy to contribute some work on this.