use {
crate::Filter,
tracing_core::{span, Event, Interest, LevelFilter, Metadata, Subscriber},
tracing_subscriber::layer::{Context, Layer},
};
pub struct FilterLayer<F> {
filter: F,
}
impl<F> FilterLayer<F> {
pub fn new(filter: F) -> Self {
Self { filter }
}
}
impl<S: Subscriber, F: 'static + Filter<S>> Layer<S> for FilterLayer<F> {
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest {
self.filter.callsite_enabled(metadata)
}
fn enabled(&self, metadata: &Metadata<'_>, ctx: Context<'_, S>) -> bool {
self.filter.enabled(metadata, &ctx)
}
fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) {
self.filter.on_new_span(attrs, id, ctx);
}
fn max_level_hint(&self) -> Option<LevelFilter> {
self.filter.max_level_hint()
}
fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) {
self.filter.on_record(id, values, ctx)
}
fn on_event(&self, _event: &Event<'_>, _ctx: Context<'_, S>) {
}
fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) {
self.filter.on_enter(id, ctx)
}
fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) {
self.filter.on_exit(id, ctx)
}
fn on_close(&self, id: span::Id, ctx: Context<'_, S>) {
self.filter.on_close(id, ctx)
}
}