Commit 219b220
committed
tracing: simplify subscriber construction with
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...Boxed layers1 parent 4b3d4b8 commit 219b220
1 file changed
+27
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
| 11 | + | |
| 12 | + | |
16 | 13 | | |
17 | 14 | | |
18 | 15 | | |
| |||
94 | 91 | | |
95 | 92 | | |
96 | 93 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
105 | 99 | | |
106 | 100 | | |
107 | 101 | | |
| |||
121 | 115 | | |
122 | 116 | | |
123 | 117 | | |
124 | | - | |
| 118 | + | |
125 | 119 | | |
126 | | - | |
| 120 | + | |
127 | 121 | | |
128 | 122 | | |
129 | 123 | | |
130 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
131 | 129 | | |
132 | 130 | | |
133 | 131 | | |
134 | 132 | | |
135 | 133 | | |
136 | | - | |
| 134 | + | |
137 | 135 | | |
138 | | - | |
| 136 | + | |
139 | 137 | | |
140 | 138 | | |
141 | 139 | | |
142 | 140 | | |
143 | | - | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
144 | 144 | | |
145 | | - | |
146 | | - | |
147 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
150 | 155 | | |
151 | 156 | | |
152 | 157 | | |
| |||
0 commit comments