Skip to content

Commit fde00c9

Browse files
committed
Let Subscribe disable specific events
1 parent a3e7944 commit fde00c9

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Diff for: tracing-subscriber/src/reload.rs

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ where
9393
try_lock!(self.inner.read()).on_follows_from(span, follows, ctx)
9494
}
9595

96+
#[inline]
97+
fn event_enabled(&self, event: &Event<'_>, ctx: subscribe::Context<'_, C>) -> bool {
98+
try_lock!(self.inner.read(), else return false).event_enabled(event, ctx)
99+
}
100+
96101
#[inline]
97102
fn on_event(&self, event: &Event<'_>, ctx: subscribe::Context<'_, C>) {
98103
try_lock!(self.inner.read()).on_event(event, ctx)

Diff for: tracing-subscriber/src/subscribe/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,30 @@ where
827827
// seems like a good future-proofing measure as it may grow other methods later...
828828
fn on_follows_from(&self, _span: &span::Id, _follows: &span::Id, _ctx: Context<'_, C>) {}
829829

830+
/// Called before `on_event`, to determine if `on_event` should be called.
831+
///
832+
/// <div class="example-wrap" style="display:inline-block">
833+
/// <pre class="ignore" style="white-space:normal;font:inherit;">
834+
///
835+
/// **Note**: This method determines whether an event is globally enabled,
836+
/// *not* whether the individual subscriber will be notified about the
837+
/// event. This is intended to be used by layers that implement filtering
838+
/// for the entire stack. Layers which do not wish to be notified about
839+
/// certain events but do not wish to globally disable them should ignore
840+
/// those events in their [on_event][Self::on_event].
841+
///
842+
/// </pre></div>
843+
///
844+
/// See [the trait-level documentation] for more information on filtering
845+
/// with `Subscriber`s.
846+
///
847+
/// [`Interest`]: tracing_core::Interest
848+
/// [the trait-level documentation]: #filtering-with-subscribers
849+
#[inline] // collapse this to a constant please mrs optimizer
850+
fn event_enabled(&self, _event: &Event<'_>, _ctx: Context<'_, C>) -> bool {
851+
true
852+
}
853+
830854
/// Notifies this subscriber that an event has occurred.
831855
fn on_event(&self, _event: &Event<'_>, _ctx: Context<'_, C>) {}
832856

0 commit comments

Comments
 (0)