You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tracing: simplify subscriber construction with Boxed 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...
(cherry picked from commit 3bb7ec4)
Signed-off-by: Oliver Gould <[email protected]>
0 commit comments