Skip to content

Commit

Permalink
Rescue on_event impls from the rebase wastes
Browse files Browse the repository at this point in the history
  • Loading branch information
CAD97 committed Mar 31, 2022
1 parent eb1dd70 commit 6968e3c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tracing-subscriber/src/subscribe/layered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ where
}

fn event(&self, event: &Event<'_>) {
self.inner.event(event);
self.subscriber.on_event(event, self.ctx());
if self.subscriber.event_enabled(event, self.ctx()) {
self.inner.event(event);
self.subscriber.on_event(event, self.ctx());
}
}

fn enter(&self, span: &span::Id) {
Expand Down Expand Up @@ -255,6 +257,17 @@ where
self.subscriber.on_follows_from(span, follows, ctx);
}

#[inline]
fn event_enabled(&self, event: &Event<'_>, ctx: Context<'_, C>) -> bool {
if self.subscriber.event_enabled(event, ctx.clone()) {
// if the outer subscriber enables the event, ask the inner subscriber.
self.inner.event_enabled(event, ctx)
} else {
// otherwise, the callsite is disabled by this subscriber
false
}
}

#[inline]
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, C>) {
self.inner.on_event(event, ctx.clone());
Expand Down
13 changes: 13 additions & 0 deletions tracing-subscriber/src/subscribe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,14 @@ where
}
}

#[inline]
fn event_enabled(&self, event: &Event<'_>, ctx: Context<'_, C>) -> bool {
match self {
Some(ref inner) => inner.event_enabled(event, ctx),
None => false,
}
}

#[inline]
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, C>) {
if let Some(ref inner) = self {
Expand Down Expand Up @@ -1583,6 +1591,11 @@ macro_rules! subscriber_impl_body {
self.deref().on_follows_from(span, follows, ctx)
}

#[inline]
fn event_enabled(&self, event: &Event<'_>, ctx: Context<'_, C>) -> bool {
self.deref().event_enabled(event, ctx)
}

#[inline]
fn on_event(&self, event: &Event<'_>, ctx: Context<'_, C>) {
self.deref().on_event(event, ctx)
Expand Down

0 comments on commit 6968e3c

Please sign in to comment.