Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tracing: simplify subscriber construction with
Box
ed layers (#1304)
Currently, the way the `tracing` subscriber is constructed is somewhat convoluted, due to potentially constructing formatting layers with different types (either plaintext logging or JSON). Because of this, we can't simply have methods that return the `fmt` layer. Instead, we have to pass the `Registry` into the methods that construct the `fmt` layers and return a type-erased `Dispatch` after adding the `fmt` layers. This is kind of not great. In particular, it makes adding additional layers difficult, such as access logging (#601) and (eventually) `tokio-console` support. This branch refactors the subscriber construction to use the (recently-added) `impl Layer<S> for Box<dyn Layer<S>>` in `tracing-subscriber`. Now, we can erase the types of the JSON and plaintext `fmt` layers and return them from the methods that construct them, and layer them onto the `Registry` in `tracing::Settings::build()`. This makes the `tracing` setup significantly easier, and will enable changes I want to make in #601. Boxing these layers does add slight overhead of dynamic dispatch + a pointer dereference. However, I doubt this has a huge performance impact in practice...
- Loading branch information