Lines Matching full:layer
1 //! Wrapper for a `Layer` to allow it to be dynamically reloaded.
3 //! This module provides a [`Layer` type] implementing the [`Layer` trait] or [`Filter` trait]
8 //! This can be used in cases where a subset of `Layer` or `Filter` functionality
10 //! change at runtime. Note that this layer introduces a (relatively small)
15 //! Reloading a [global filtering](crate::layer#global-filtering) layer:
21 //! let (filter, reload_handle) = reload::Layer::new(filter);
24 //! .with(fmt::Layer::default())
35 //! Reloading a [`Filtered`](crate::filter::Filtered) layer:
40 //! let filtered_layer = fmt::Layer::default().with_filter(filter::LevelFilter::WARN);
41 //! let (filtered_layer, reload_handle) = reload::Layer::new(filtered_layer);
44 //! # let _: &reload::Handle<filter::Filtered<fmt::Layer<tracing_subscriber::Registry>,
52 //! reload_handle.modify(|layer| *layer.filter_mut() = filter::LevelFilter::INFO);
58 //! The [`Layer`] implementation is unable to implement downcasting functionality,
59 //! so certain [`Layer`] will fail to downcast if wrapped in a `reload::Layer`.
62 //! `Filter` on a layer, prefer wrapping that `Filter` in the `reload::Layer`.
64 //! [`Filter` trait]: crate::layer::Filter
65 //! [`Layer` type]: Layer
66 //! [`Layer` trait]: super::layer::Layer
67 use crate::layer;
82 /// Wraps a `Layer` or `Filter`, allowing it to be reloaded dynamically at runtime.
84 pub struct Layer<L, S> { struct
93 /// Allows reloading the state of an associated [`Layer`](crate::layer::Layer). argument
100 /// Indicates that an error occurred when reloading a layer.
112 // ===== impl Layer =====
114 impl<L, S> crate::Layer<S> for Layer<L, S> implementation
116 L: crate::Layer<S> + 'static,
133 fn enabled(&self, metadata: &Metadata<'_>, ctx: layer::Context<'_, S>) -> bool { in enabled()
138 fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: layer::Context<'_, S>) { in on_new_span()
143 fn on_record(&self, span: &span::Id, values: &span::Record<'_>, ctx: layer::Context<'_, S>) { in on_record()
148 fn on_follows_from(&self, span: &span::Id, follows: &span::Id, ctx: layer::Context<'_, S>) { in on_follows_from()
153 fn event_enabled(&self, event: &Event<'_>, ctx: layer::Context<'_, S>) -> bool { in event_enabled()
158 fn on_event(&self, event: &Event<'_>, ctx: layer::Context<'_, S>) { in on_event()
163 fn on_enter(&self, id: &span::Id, ctx: layer::Context<'_, S>) { in on_enter()
168 fn on_exit(&self, id: &span::Id, ctx: layer::Context<'_, S>) { in on_exit()
173 fn on_close(&self, id: span::Id, ctx: layer::Context<'_, S>) { in on_close()
178 fn on_id_change(&self, old: &span::Id, new: &span::Id, ctx: layer::Context<'_, S>) { in on_id_change()
199 if id == TypeId::of::<layer::NoneLayerMarker>() { in downcast_raw()
211 impl<S, L> crate::layer::Filter<S> for Layer<L, S> implementation
213 L: crate::layer::Filter<S> + 'static,
222 fn enabled(&self, metadata: &Metadata<'_>, ctx: &layer::Context<'_, S>) -> bool { in enabled()
227 fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: layer::Context<'_, S>) { in on_new_span()
232 fn on_record(&self, span: &span::Id, values: &span::Record<'_>, ctx: layer::Context<'_, S>) { in on_record()
237 fn on_enter(&self, id: &span::Id, ctx: layer::Context<'_, S>) { in on_enter()
242 fn on_exit(&self, id: &span::Id, ctx: layer::Context<'_, S>) { in on_exit()
247 fn on_close(&self, id: span::Id, ctx: layer::Context<'_, S>) { in on_close()
257 impl<L, S> Layer<L, S> { implementation
258 /// Wraps the given [`Layer`] or [`Filter`], returning a `reload::Layer`
261 /// [`Layer`]: crate::layer::Layer
262 /// [`Filter`]: crate::layer::Filter
272 /// Returns a `Handle` that can be used to reload the wrapped [`Layer`] or [`Filter`].
274 /// [`Layer`]: crate::layer::Layer
287 /// Replace the current [`Layer`] or [`Filter`] with the provided `new_value`.
289 /// [`Handle::reload`] cannot be used with the [`Filtered`] layer; use
293 /// `reload::Layer` to wrap the `Filter` directly.
295 /// [`Layer`]: crate::layer::Layer
296 /// [`Filter`]: crate::layer::Filter
301 self.modify(|layer| { in reload()
302 *layer = new_value.into(); in reload()
306 /// Invokes a closure with a mutable reference to the current layer or filter,
316 // function will lock the new layer. in modify()
323 /// Returns a clone of the layer or filter's current value if it still exists.
332 /// Invokes a closure with a borrowed reference to the current layer or filter,
361 /// Returns `true` if this error occurred because the layer was poisoned by
368 /// containing the reloadable layer was dropped.