Coverage Report

Created: 2025-11-16 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/tracing-subscriber-0.3.20/src/layer/layered.rs
Line
Count
Source
1
use tracing_core::{metadata::Metadata, span, Dispatch, Event, Interest, LevelFilter, Subscriber};
2
3
use crate::{
4
    filter,
5
    layer::{Context, Layer},
6
    registry::LookupSpan,
7
};
8
#[cfg(all(feature = "registry", feature = "std"))]
9
use crate::{filter::FilterId, registry::Registry};
10
use core::{
11
    any::{Any, TypeId},
12
    cmp, fmt,
13
    marker::PhantomData,
14
};
15
16
/// A [`Subscriber`] composed of a `Subscriber` wrapped by one or more
17
/// [`Layer`]s.
18
///
19
/// [`Layer`]: crate::Layer
20
/// [`Subscriber`]: tracing_core::Subscriber
21
#[derive(Clone)]
22
pub struct Layered<L, I, S = I> {
23
    /// The layer.
24
    layer: L,
25
26
    /// The inner value that `self.layer` was layered onto.
27
    ///
28
    /// If this is also a `Layer`, then this `Layered` will implement `Layer`.
29
    /// If this is a `Subscriber`, then this `Layered` will implement
30
    /// `Subscriber` instead.
31
    inner: I,
32
33
    // These booleans are used to determine how to combine `Interest`s and max
34
    // level hints when per-layer filters are in use.
35
    /// Is `self.inner` a `Registry`?
36
    ///
37
    /// If so, when combining `Interest`s, we want to "bubble up" its
38
    /// `Interest`.
39
    inner_is_registry: bool,
40
41
    /// Does `self.layer` have per-layer filters?
42
    ///
43
    /// This will be true if:
44
    /// - `self.inner` is a `Filtered`.
45
    /// - `self.inner` is a tree of `Layered`s where _all_ arms of those
46
    ///   `Layered`s have per-layer filters.
47
    ///
48
    /// Otherwise, if it's a `Layered` with one per-layer filter in one branch,
49
    /// but a non-per-layer-filtered layer in the other branch, this will be
50
    /// _false_, because the `Layered` is already handling the combining of
51
    /// per-layer filter `Interest`s and max level hints with its non-filtered
52
    /// `Layer`.
53
    has_layer_filter: bool,
54
55
    /// Does `self.inner` have per-layer filters?
56
    ///
57
    /// This is determined according to the same rules as
58
    /// `has_layer_filter` above.
59
    inner_has_layer_filter: bool,
60
    _s: PhantomData<fn(S)>,
61
}
62
63
// === impl Layered ===
64
65
impl<L, S> Layered<L, S>
66
where
67
    L: Layer<S>,
68
    S: Subscriber,
69
{
70
    /// Returns `true` if this [`Subscriber`] is the same type as `T`.
71
0
    pub fn is<T: Any>(&self) -> bool {
72
0
        self.downcast_ref::<T>().is_some()
73
0
    }
74
75
    /// Returns some reference to this [`Subscriber`] value if it is of type `T`,
76
    /// or `None` if it isn't.
77
0
    pub fn downcast_ref<T: Any>(&self) -> Option<&T> {
78
        unsafe {
79
0
            let raw = self.downcast_raw(TypeId::of::<T>())?;
80
0
            if raw.is_null() {
81
0
                None
82
            } else {
83
0
                Some(&*(raw as *const T))
84
            }
85
        }
86
0
    }
87
}
88
89
impl<L, S> Subscriber for Layered<L, S>
90
where
91
    L: Layer<S>,
92
    S: Subscriber,
93
{
94
0
    fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
95
0
        self.pick_interest(self.layer.register_callsite(metadata), || {
96
0
            self.inner.register_callsite(metadata)
97
0
        })
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::register_callsite::{closure#0}
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::register_callsite::{closure#0}
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::register_callsite::{closure#0}
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::register_callsite::{closure#0}
98
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::register_callsite
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::register_callsite
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::register_callsite
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::register_callsite
99
100
0
    fn enabled(&self, metadata: &Metadata<'_>) -> bool {
101
0
        if self.layer.enabled(metadata, self.ctx()) {
102
            // if the outer layer enables the callsite metadata, ask the subscriber.
103
0
            self.inner.enabled(metadata)
104
        } else {
105
            // otherwise, the callsite is disabled by the layer
106
107
            // If per-layer filters are in use, and we are short-circuiting
108
            // (rather than calling into the inner type), clear the current
109
            // per-layer filter `enabled` state.
110
            #[cfg(feature = "registry")]
111
0
            filter::FilterState::clear_enabled();
112
113
0
            false
114
        }
115
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::enabled
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::enabled
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::enabled
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::enabled
116
117
0
    fn max_level_hint(&self) -> Option<LevelFilter> {
118
0
        self.pick_level_hint(
119
0
            self.layer.max_level_hint(),
120
0
            self.inner.max_level_hint(),
121
0
            super::subscriber_is_none(&self.inner),
122
        )
123
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::max_level_hint
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::max_level_hint
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::max_level_hint
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::max_level_hint
124
125
0
    fn new_span(&self, span: &span::Attributes<'_>) -> span::Id {
126
0
        let id = self.inner.new_span(span);
127
0
        self.layer.on_new_span(span, &id, self.ctx());
128
0
        id
129
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::new_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::new_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::new_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::new_span
130
131
0
    fn record(&self, span: &span::Id, values: &span::Record<'_>) {
132
0
        self.inner.record(span, values);
133
0
        self.layer.on_record(span, values, self.ctx());
134
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::record
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::record
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::record
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::record
135
136
0
    fn record_follows_from(&self, span: &span::Id, follows: &span::Id) {
137
0
        self.inner.record_follows_from(span, follows);
138
0
        self.layer.on_follows_from(span, follows, self.ctx());
139
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::record_follows_from
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::record_follows_from
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::record_follows_from
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::record_follows_from
140
141
0
    fn event_enabled(&self, event: &Event<'_>) -> bool {
142
0
        if self.layer.event_enabled(event, self.ctx()) {
143
            // if the outer layer enables the event, ask the inner subscriber.
144
0
            self.inner.event_enabled(event)
145
        } else {
146
            // otherwise, the event is disabled by this layer
147
0
            false
148
        }
149
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::event_enabled
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::event_enabled
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::event_enabled
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::event_enabled
150
151
0
    fn event(&self, event: &Event<'_>) {
152
0
        self.inner.event(event);
153
0
        self.layer.on_event(event, self.ctx());
154
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::event
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::event
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::event
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::event
155
156
0
    fn enter(&self, span: &span::Id) {
157
0
        self.inner.enter(span);
158
0
        self.layer.on_enter(span, self.ctx());
159
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::enter
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::enter
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::enter
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::enter
160
161
0
    fn exit(&self, span: &span::Id) {
162
0
        self.inner.exit(span);
163
0
        self.layer.on_exit(span, self.ctx());
164
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::exit
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::exit
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::exit
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::exit
165
166
0
    fn clone_span(&self, old: &span::Id) -> span::Id {
167
0
        let new = self.inner.clone_span(old);
168
0
        if &new != old {
169
0
            self.layer.on_id_change(old, &new, self.ctx())
170
0
        };
171
0
        new
172
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::clone_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::clone_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::clone_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::clone_span
173
174
    #[inline]
175
0
    fn drop_span(&self, id: span::Id) {
176
0
        self.try_close(id);
177
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::drop_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::drop_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::drop_span
178
179
0
    fn try_close(&self, id: span::Id) -> bool {
180
        #[cfg(all(feature = "registry", feature = "std"))]
181
0
        let subscriber = &self.inner as &dyn Subscriber;
182
        #[cfg(all(feature = "registry", feature = "std"))]
183
0
        let mut guard = subscriber
184
0
            .downcast_ref::<Registry>()
185
0
            .map(|registry| registry.start_close(id.clone()));
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::try_close::{closure#0}
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::try_close::{closure#0}
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::try_close::{closure#0}
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::try_close::{closure#0}
186
0
        if self.inner.try_close(id.clone()) {
187
            // If we have a registry's close guard, indicate that the span is
188
            // closing.
189
            #[cfg(all(feature = "registry", feature = "std"))]
190
            {
191
0
                if let Some(g) = guard.as_mut() {
192
0
                    g.set_closing()
193
0
                };
194
            }
195
196
0
            self.layer.on_close(id, self.ctx());
197
0
            true
198
        } else {
199
0
            false
200
        }
201
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::try_close
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::try_close
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::try_close
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::try_close
202
203
    #[inline]
204
0
    fn current_span(&self) -> span::Current {
205
0
        self.inner.current_span()
206
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::current_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::current_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::current_span
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::current_span
207
208
    #[doc(hidden)]
209
0
    unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {
210
        // Unlike the implementation of `Layer` for `Layered`, we don't have to
211
        // handle the "magic PLF downcast marker" here. If a `Layered`
212
        // implements `Subscriber`, we already know that the `inner` branch is
213
        // going to contain something that doesn't have per-layer filters (the
214
        // actual root `Subscriber`). Thus, a `Layered` that implements
215
        // `Subscriber` will always be propagating the root subscriber's
216
        // `Interest`/level hint, even if it includes a `Layer` that has
217
        // per-layer filters, because it will only ever contain layers where
218
        // _one_ child has per-layer filters.
219
        //
220
        // The complex per-layer filter detection logic is only relevant to
221
        // *trees* of layers, which involve the `Layer` implementation for
222
        // `Layered`, not *lists* of layers, where every `Layered` implements
223
        // `Subscriber`. Of course, a linked list can be thought of as a
224
        // degenerate tree...but luckily, we are able to make a type-level
225
        // distinction between individual `Layered`s that are definitely
226
        // list-shaped (their inner child implements `Subscriber`), and
227
        // `Layered`s that might be tree-shaped (the inner child is also a
228
        // `Layer`).
229
230
        // If downcasting to `Self`, return a pointer to `self`.
231
0
        if id == TypeId::of::<Self>() {
232
0
            return Some(self as *const _ as *const ());
233
0
        }
234
235
0
        self.layer
236
0
            .downcast_raw(id)
237
0
            .or_else(|| self.inner.downcast_raw(id))
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::downcast_raw::{closure#0}
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::downcast_raw::{closure#0}
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::downcast_raw::{closure#0}
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::downcast_raw::{closure#0}
238
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::downcast_raw
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::downcast_raw
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::downcast_raw
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::downcast_raw
239
}
240
241
impl<S, A, B> Layer<S> for Layered<A, B, S>
242
where
243
    A: Layer<S>,
244
    B: Layer<S>,
245
    S: Subscriber,
246
{
247
0
    fn on_register_dispatch(&self, subscriber: &Dispatch) {
248
0
        self.layer.on_register_dispatch(subscriber);
249
0
        self.inner.on_register_dispatch(subscriber);
250
0
    }
251
252
0
    fn on_layer(&mut self, subscriber: &mut S) {
253
0
        self.layer.on_layer(subscriber);
254
0
        self.inner.on_layer(subscriber);
255
0
    }
256
257
0
    fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
258
0
        self.pick_interest(self.layer.register_callsite(metadata), || {
259
0
            self.inner.register_callsite(metadata)
260
0
        })
261
0
    }
262
263
0
    fn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool {
264
0
        if self.layer.enabled(metadata, ctx.clone()) {
265
            // if the outer subscriber enables the callsite metadata, ask the inner layer.
266
0
            self.inner.enabled(metadata, ctx)
267
        } else {
268
            // otherwise, the callsite is disabled by this layer
269
0
            false
270
        }
271
0
    }
272
273
0
    fn max_level_hint(&self) -> Option<LevelFilter> {
274
0
        self.pick_level_hint(
275
0
            self.layer.max_level_hint(),
276
0
            self.inner.max_level_hint(),
277
0
            super::layer_is_none(&self.inner),
278
        )
279
0
    }
280
281
    #[inline]
282
0
    fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
283
0
        self.inner.on_new_span(attrs, id, ctx.clone());
284
0
        self.layer.on_new_span(attrs, id, ctx);
285
0
    }
286
287
    #[inline]
288
0
    fn on_record(&self, span: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
289
0
        self.inner.on_record(span, values, ctx.clone());
290
0
        self.layer.on_record(span, values, ctx);
291
0
    }
292
293
    #[inline]
294
0
    fn on_follows_from(&self, span: &span::Id, follows: &span::Id, ctx: Context<'_, S>) {
295
0
        self.inner.on_follows_from(span, follows, ctx.clone());
296
0
        self.layer.on_follows_from(span, follows, ctx);
297
0
    }
298
299
    #[inline]
300
0
    fn event_enabled(&self, event: &Event<'_>, ctx: Context<'_, S>) -> bool {
301
0
        if self.layer.event_enabled(event, ctx.clone()) {
302
            // if the outer layer enables the event, ask the inner subscriber.
303
0
            self.inner.event_enabled(event, ctx)
304
        } else {
305
            // otherwise, the event is disabled by this layer
306
0
            false
307
        }
308
0
    }
309
310
    #[inline]
311
0
    fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) {
312
0
        self.inner.on_event(event, ctx.clone());
313
0
        self.layer.on_event(event, ctx);
314
0
    }
315
316
    #[inline]
317
0
    fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) {
318
0
        self.inner.on_enter(id, ctx.clone());
319
0
        self.layer.on_enter(id, ctx);
320
0
    }
321
322
    #[inline]
323
0
    fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) {
324
0
        self.inner.on_exit(id, ctx.clone());
325
0
        self.layer.on_exit(id, ctx);
326
0
    }
327
328
    #[inline]
329
0
    fn on_close(&self, id: span::Id, ctx: Context<'_, S>) {
330
0
        self.inner.on_close(id.clone(), ctx.clone());
331
0
        self.layer.on_close(id, ctx);
332
0
    }
333
334
    #[inline]
335
0
    fn on_id_change(&self, old: &span::Id, new: &span::Id, ctx: Context<'_, S>) {
336
0
        self.inner.on_id_change(old, new, ctx.clone());
337
0
        self.layer.on_id_change(old, new, ctx);
338
0
    }
339
340
    #[doc(hidden)]
341
0
    unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()> {
342
0
        match id {
343
            // If downcasting to `Self`, return a pointer to `self`.
344
0
            id if id == TypeId::of::<Self>() => Some(self as *const _ as *const ()),
345
346
            // Oh, we're looking for per-layer filters!
347
            //
348
            // This should only happen if we are inside of another `Layered`,
349
            // and it's trying to determine how it should combine `Interest`s
350
            // and max level hints.
351
            //
352
            // In that case, this `Layered` should be considered to be
353
            // "per-layer filtered" if *both* the outer layer and the inner
354
            // layer/subscriber have per-layer filters. Otherwise, this `Layered
355
            // should *not* be considered per-layer filtered (even if one or the
356
            // other has per layer filters). If only one `Layer` is per-layer
357
            // filtered, *this* `Layered` will handle aggregating the `Interest`
358
            // and level hints on behalf of its children, returning the
359
            // aggregate (which is the value from the &non-per-layer-filtered*
360
            // child).
361
            //
362
            // Yes, this rule *is* slightly counter-intuitive, but it's
363
            // necessary due to a weird edge case that can occur when two
364
            // `Layered`s where one side is per-layer filtered and the other
365
            // isn't are `Layered` together to form a tree. If we didn't have
366
            // this rule, we would actually end up *ignoring* `Interest`s from
367
            // the non-per-layer-filtered layers, since both branches would
368
            // claim to have PLF.
369
            //
370
            // If you don't understand this...that's fine, just don't mess with
371
            // it. :)
372
0
            id if filter::is_plf_downcast_marker(id) => {
373
0
                self.layer.downcast_raw(id).and(self.inner.downcast_raw(id))
374
            }
375
376
            // Otherwise, try to downcast both branches normally...
377
0
            _ => self
378
0
                .layer
379
0
                .downcast_raw(id)
380
0
                .or_else(|| self.inner.downcast_raw(id)),
381
        }
382
0
    }
383
}
384
385
impl<'a, L, S> LookupSpan<'a> for Layered<L, S>
386
where
387
    S: Subscriber + LookupSpan<'a>,
388
{
389
    type Data = S::Data;
390
391
0
    fn span_data(&'a self, id: &span::Id) -> Option<Self::Data> {
392
0
        self.inner.span_data(id)
393
0
    }
394
395
    #[cfg(all(feature = "registry", feature = "std"))]
396
0
    fn register_filter(&mut self) -> FilterId {
397
0
        self.inner.register_filter()
398
0
    }
399
}
400
401
impl<L, S> Layered<L, S>
402
where
403
    S: Subscriber,
404
{
405
0
    fn ctx(&self) -> Context<'_, S> {
406
0
        Context::new(&self.inner)
407
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry>>::ctx
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>>::ctx
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>>>::ctx
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber>>::ctx
408
}
409
410
impl<A, B, S> Layered<A, B, S>
411
where
412
    A: Layer<S>,
413
    S: Subscriber,
414
{
415
0
    pub(super) fn new(layer: A, inner: B, inner_has_layer_filter: bool) -> Self {
416
        #[cfg(all(feature = "registry", feature = "std"))]
417
0
        let inner_is_registry = TypeId::of::<S>() == TypeId::of::<crate::registry::Registry>();
418
419
        #[cfg(not(all(feature = "registry", feature = "std")))]
420
        let inner_is_registry = false;
421
422
0
        let inner_has_layer_filter = inner_has_layer_filter || inner_is_registry;
423
0
        let has_layer_filter = filter::layer_has_plf(&layer);
424
0
        Self {
425
0
            layer,
426
0
            inner,
427
0
            has_layer_filter,
428
0
            inner_has_layer_filter,
429
0
            inner_is_registry,
430
0
            _s: PhantomData,
431
0
        }
432
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry>>::new
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>>::new
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>>>::new
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber>>::new
433
434
0
    fn pick_interest(&self, outer: Interest, inner: impl FnOnce() -> Interest) -> Interest {
435
0
        if self.has_layer_filter {
436
0
            return inner();
437
0
        }
438
439
        // If the outer layer has disabled the callsite, return now so that
440
        // the inner layer/subscriber doesn't get its hopes up.
441
0
        if outer.is_never() {
442
            // If per-layer filters are in use, and we are short-circuiting
443
            // (rather than calling into the inner type), clear the current
444
            // per-layer filter interest state.
445
            #[cfg(feature = "registry")]
446
0
            filter::FilterState::take_interest();
447
448
0
            return outer;
449
0
        }
450
451
        // The `inner` closure will call `inner.register_callsite()`. We do this
452
        // before the `if` statement to  ensure that the inner subscriber is
453
        // informed that the callsite exists regardless of the outer layer's
454
        // filtering decision.
455
0
        let inner = inner();
456
0
        if outer.is_sometimes() {
457
            // if this interest is "sometimes", return "sometimes" to ensure that
458
            // filters are reevaluated.
459
0
            return outer;
460
0
        }
461
462
        // If there is a per-layer filter in the `inner` stack, and it returns
463
        // `never`, change the interest to `sometimes`, because the `outer`
464
        // layer didn't return `never`. This means that _some_ layer still wants
465
        // to see that callsite, even though the inner stack's per-layer filter
466
        // didn't want it. Therefore, returning `sometimes` will ensure
467
        // `enabled` is called so that the per-layer filter can skip that
468
        // span/event, while the `outer` layer still gets to see it.
469
0
        if inner.is_never() && self.inner_has_layer_filter {
470
0
            return Interest::sometimes();
471
0
        }
472
473
        // otherwise, allow the inner subscriber or subscriber to weigh in.
474
0
        inner
475
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry>>::pick_interest::<<tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::register_callsite::{closure#0}>
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>>::pick_interest::<<tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry> as tracing_core::subscriber::Subscriber>::register_callsite::{closure#0}>
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>>>::pick_interest::<<tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>> as tracing_core::subscriber::Subscriber>::register_callsite::{closure#0}>
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber>>::pick_interest::<<tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber> as tracing_core::subscriber::Subscriber>::register_callsite::{closure#0}>
476
477
0
    fn pick_level_hint(
478
0
        &self,
479
0
        outer_hint: Option<LevelFilter>,
480
0
        inner_hint: Option<LevelFilter>,
481
0
        inner_is_none: bool,
482
0
    ) -> Option<LevelFilter> {
483
0
        if self.inner_is_registry {
484
0
            return outer_hint;
485
0
        }
486
487
0
        if self.has_layer_filter && self.inner_has_layer_filter {
488
0
            return Some(cmp::max(outer_hint?, inner_hint?));
489
0
        }
490
491
0
        if self.has_layer_filter && inner_hint.is_none() {
492
0
            return None;
493
0
        }
494
495
0
        if self.inner_has_layer_filter && outer_hint.is_none() {
496
0
            return None;
497
0
        }
498
499
        // If the layer is `Option::None`, then we
500
        // want to short-circuit the layer underneath, if it
501
        // returns `None`, to override the `None` layer returning
502
        // `Some(OFF)`, which should ONLY apply when there are
503
        // no other layers that return `None`. Note this
504
        // `None` does not == `Some(TRACE)`, it means
505
        // something more like: "whatever all the other
506
        // layers agree on, default to `TRACE` if none
507
        // have an opinion". We also choose do this AFTER
508
        // we check for per-layer filters, which
509
        // have their own logic.
510
        //
511
        // Also note that this does come at some perf cost, but
512
        // this function is only called on initialization and
513
        // subscriber reloading.
514
0
        if super::layer_is_none(&self.layer) {
515
0
            return cmp::max(outer_hint, Some(inner_hint?));
516
0
        }
517
518
        // Similarly, if the layer on the inside is `None` and it returned an
519
        // `Off` hint, we want to override that with the outer hint.
520
0
        if inner_is_none && inner_hint == Some(LevelFilter::OFF) {
521
0
            return outer_hint;
522
0
        }
523
524
0
        cmp::max(outer_hint, inner_hint)
525
0
    }
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_tree::HierarchicalLayer<tracing_subscriber::fmt::writer::TestWriter>, tracing_subscriber::registry::sharded::Registry>>::pick_level_hint
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>>::pick_level_hint
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_core::metadata::LevelFilter, tracing_subscriber::layer::layered::Layered<tracing_subscriber::fmt::fmt_layer::Layer<tracing_subscriber::registry::sharded::Registry>, tracing_subscriber::registry::sharded::Registry>>>::pick_level_hint
Unexecuted instantiation: <tracing_subscriber::layer::layered::Layered<tracing_subscriber::filter::targets::Targets, tracing_subscriber::fmt::Subscriber>>::pick_level_hint
526
}
527
528
impl<A, B, S> fmt::Debug for Layered<A, B, S>
529
where
530
    A: fmt::Debug,
531
    B: fmt::Debug,
532
{
533
0
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
534
        #[cfg(all(feature = "registry", feature = "std"))]
535
0
        let alt = f.alternate();
536
0
        let mut s = f.debug_struct("Layered");
537
        // These additional fields are more verbose and usually only necessary
538
        // for internal debugging purposes, so only print them if alternate mode
539
        // is enabled.
540
541
        #[cfg(all(feature = "registry", feature = "std"))]
542
        {
543
0
            if alt {
544
0
                s.field("inner_is_registry", &self.inner_is_registry)
545
0
                    .field("has_layer_filter", &self.has_layer_filter)
546
0
                    .field("inner_has_layer_filter", &self.inner_has_layer_filter);
547
0
            }
548
        }
549
550
0
        s.field("layer", &self.layer)
551
0
            .field("inner", &self.inner)
552
0
            .finish()
553
0
    }
554
}