summaryrefslogtreecommitdiffstats
path: root/vendor/tracing-subscriber-0.3.3/src/reload.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--vendor/tracing-subscriber-0.3.3/src/reload.rs (renamed from vendor/tracing-subscriber/src/reload.rs)171
1 files changed, 24 insertions, 147 deletions
diff --git a/vendor/tracing-subscriber/src/reload.rs b/vendor/tracing-subscriber-0.3.3/src/reload.rs
index 0c6c1c45c..b8ec67dfa 100644
--- a/vendor/tracing-subscriber/src/reload.rs
+++ b/vendor/tracing-subscriber-0.3.3/src/reload.rs
@@ -1,69 +1,16 @@
//! Wrapper for a `Layer` to allow it to be dynamically reloaded.
//!
-//! This module provides a [`Layer` type] implementing the [`Layer` trait] or [`Filter` trait]
-//! which wraps another type implementing the corresponding trait. This
-//! allows the wrapped type to be replaced with another
+//! This module provides a [`Layer` type] which wraps another type implementing
+//! the [`Layer` trait], allowing the wrapped type to be replaced with another
//! instance of that type at runtime.
//!
-//! This can be used in cases where a subset of `Layer` or `Filter` functionality
+//! This can be used in cases where a subset of `Subscriber` functionality
//! should be dynamically reconfigured, such as when filtering directives may
//! change at runtime. Note that this layer introduces a (relatively small)
//! amount of overhead, and should thus only be used as needed.
//!
-//! # Examples
-//!
-//! Reloading a [global filtering](crate::layer#global-filtering) layer:
-//!
-//! ```rust
-//! # use tracing::info;
-//! use tracing_subscriber::{filter, fmt, reload, prelude::*};
-//! let filter = filter::LevelFilter::WARN;
-//! let (filter, reload_handle) = reload::Layer::new(filter);
-//! tracing_subscriber::registry()
-//! .with(filter)
-//! .with(fmt::Layer::default())
-//! .init();
-//! #
-//! # // specifying the Registry type is required
-//! # let _: &reload::Handle<filter::LevelFilter, tracing_subscriber::Registry> = &reload_handle;
-//! #
-//! info!("This will be ignored");
-//! reload_handle.modify(|filter| *filter = filter::LevelFilter::INFO);
-//! info!("This will be logged");
-//! ```
-//!
-//! Reloading a [`Filtered`](crate::filter::Filtered) layer:
-//!
-//! ```rust
-//! # use tracing::info;
-//! use tracing_subscriber::{filter, fmt, reload, prelude::*};
-//! let filtered_layer = fmt::Layer::default().with_filter(filter::LevelFilter::WARN);
-//! let (filtered_layer, reload_handle) = reload::Layer::new(filtered_layer);
-//! #
-//! # // specifying the Registry type is required
-//! # let _: &reload::Handle<filter::Filtered<fmt::Layer<tracing_subscriber::Registry>,
-//! # filter::LevelFilter, tracing_subscriber::Registry>,tracing_subscriber::Registry>
-//! # = &reload_handle;
-//! #
-//! tracing_subscriber::registry()
-//! .with(filtered_layer)
-//! .init();
-//! info!("This will be ignored");
-//! reload_handle.modify(|layer| *layer.filter_mut() = filter::LevelFilter::INFO);
-//! info!("This will be logged");
-//! ```
-//!
-//! ## Note
-//!
-//! The [`Layer`] implementation is unable to implement downcasting functionality,
-//! so certain [`Layer`] will fail to downcast if wrapped in a `reload::Layer`.
-//!
-//! If you only want to be able to dynamically change the
-//! `Filter` on a layer, prefer wrapping that `Filter` in the `reload::Layer`.
-//!
-//! [`Filter` trait]: crate::layer::Filter
-//! [`Layer` type]: Layer
-//! [`Layer` trait]: super::layer::Layer
+//! [`Layer` type]: struct.Layer.html
+//! [`Layer` trait]: ../layer/trait.Layer.html
use crate::layer;
use crate::sync::RwLock;
@@ -75,10 +22,10 @@ use std::{
use tracing_core::{
callsite, span,
subscriber::{Interest, Subscriber},
- Event, LevelFilter, Metadata,
+ Event, Metadata,
};
-/// Wraps a `Layer` or `Filter`, allowing it to be reloaded dynamically at runtime.
+/// Wraps a `Layer`, allowing it to be reloaded dynamically at runtime.
#[derive(Debug)]
pub struct Layer<L, S> {
// TODO(eliza): this once used a `crossbeam_util::ShardedRwLock`. We may
@@ -89,7 +36,7 @@ pub struct Layer<L, S> {
_s: PhantomData<fn(S)>,
}
-/// Allows reloading the state of an associated [`Layer`](crate::layer::Layer).
+/// Allows reloading the state of an associated `Layer`.
#[derive(Debug)]
pub struct Handle<L, S> {
inner: Weak<RwLock<L>>,
@@ -145,11 +92,6 @@ where
}
#[inline]
- fn event_enabled(&self, event: &Event<'_>, ctx: layer::Context<'_, S>) -> bool {
- try_lock!(self.inner.read(), else return false).event_enabled(event, ctx)
- }
-
- #[inline]
fn on_event(&self, event: &Event<'_>, ctx: layer::Context<'_, S>) {
try_lock!(self.inner.read()).on_event(event, ctx)
}
@@ -173,69 +115,15 @@ where
fn on_id_change(&self, old: &span::Id, new: &span::Id, ctx: layer::Context<'_, S>) {
try_lock!(self.inner.read()).on_id_change(old, new, ctx)
}
-
- #[inline]
- fn max_level_hint(&self) -> Option<LevelFilter> {
- try_lock!(self.inner.read(), else return None).max_level_hint()
- }
}
-// ===== impl Filter =====
-
-#[cfg(all(feature = "registry", feature = "std"))]
-#[cfg_attr(docsrs, doc(cfg(all(feature = "registry", feature = "std"))))]
-impl<S, L> crate::layer::Filter<S> for Layer<L, S>
+impl<L, S> Layer<L, S>
where
- L: crate::layer::Filter<S> + 'static,
+ L: crate::Layer<S> + 'static,
S: Subscriber,
{
- #[inline]
- fn callsite_enabled(&self, metadata: &'static Metadata<'static>) -> Interest {
- try_lock!(self.inner.read(), else return Interest::sometimes()).callsite_enabled(metadata)
- }
-
- #[inline]
- fn enabled(&self, metadata: &Metadata<'_>, ctx: &layer::Context<'_, S>) -> bool {
- try_lock!(self.inner.read(), else return false).enabled(metadata, ctx)
- }
-
- #[inline]
- fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: layer::Context<'_, S>) {
- try_lock!(self.inner.read()).on_new_span(attrs, id, ctx)
- }
-
- #[inline]
- fn on_record(&self, span: &span::Id, values: &span::Record<'_>, ctx: layer::Context<'_, S>) {
- try_lock!(self.inner.read()).on_record(span, values, ctx)
- }
-
- #[inline]
- fn on_enter(&self, id: &span::Id, ctx: layer::Context<'_, S>) {
- try_lock!(self.inner.read()).on_enter(id, ctx)
- }
-
- #[inline]
- fn on_exit(&self, id: &span::Id, ctx: layer::Context<'_, S>) {
- try_lock!(self.inner.read()).on_exit(id, ctx)
- }
-
- #[inline]
- fn on_close(&self, id: span::Id, ctx: layer::Context<'_, S>) {
- try_lock!(self.inner.read()).on_close(id, ctx)
- }
-
- #[inline]
- fn max_level_hint(&self) -> Option<LevelFilter> {
- try_lock!(self.inner.read(), else return None).max_level_hint()
- }
-}
-
-impl<L, S> Layer<L, S> {
- /// Wraps the given [`Layer`] or [`Filter`], returning a `reload::Layer`
- /// and a `Handle` that allows the inner value to be modified at runtime.
- ///
- /// [`Layer`]: crate::layer::Layer
- /// [`Filter`]: crate::layer::Filter
+ /// Wraps the given `Layer`, returning a `Layer` and a `Handle` that allows
+ /// the inner type to be modified at runtime.
pub fn new(inner: L) -> (Self, Handle<L, S>) {
let this = Self {
inner: Arc::new(RwLock::new(inner)),
@@ -245,10 +133,7 @@ impl<L, S> Layer<L, S> {
(this, handle)
}
- /// Returns a `Handle` that can be used to reload the wrapped [`Layer`] or [`Filter`].
- ///
- /// [`Layer`]: crate::layer::Layer
- /// [`Filter`]: crate::filter::Filter
+ /// Returns a `Handle` that can be used to reload the wrapped `Layer`.
pub fn handle(&self) -> Handle<L, S> {
Handle {
inner: Arc::downgrade(&self.inner),
@@ -259,27 +144,19 @@ impl<L, S> Layer<L, S> {
// ===== impl Handle =====
-impl<L, S> Handle<L, S> {
- /// Replace the current [`Layer`] or [`Filter`] with the provided `new_value`.
- ///
- /// [`Handle::reload`] cannot be used with the [`Filtered`] layer; use
- /// [`Handle::modify`] instead (see [this issue] for additional details).
- ///
- /// However, if the _only_ the [`Filter`] needs to be modified, use
- /// `reload::Layer` to wrap the `Filter` directly.
- ///
- /// [`Layer`]: crate::layer::Layer
- /// [`Filter`]: crate::layer::Filter
- /// [`Filtered`]: crate::filter::Filtered
- ///
- /// [this issue]: https://github.com/tokio-rs/tracing/issues/1629
- pub fn reload(&self, new_value: impl Into<L>) -> Result<(), Error> {
+impl<L, S> Handle<L, S>
+where
+ L: crate::Layer<S> + 'static,
+ S: Subscriber,
+{
+ /// Replace the current layer with the provided `new_layer`.
+ pub fn reload(&self, new_layer: impl Into<L>) -> Result<(), Error> {
self.modify(|layer| {
- *layer = new_value.into();
+ *layer = new_layer.into();
})
}
- /// Invokes a closure with a mutable reference to the current layer or filter,
+ /// Invokes a closure with a mutable reference to the current layer,
/// allowing it to be modified in place.
pub fn modify(&self, f: impl FnOnce(&mut L)) -> Result<(), Error> {
let inner = self.inner.upgrade().ok_or(Error {
@@ -296,7 +173,7 @@ impl<L, S> Handle<L, S> {
Ok(())
}
- /// Returns a clone of the layer or filter's current value if it still exists.
+ /// Returns a clone of the layer's current value if it still exists.
/// Otherwise, if the subscriber has been dropped, returns `None`.
pub fn clone_current(&self) -> Option<L>
where
@@ -305,7 +182,7 @@ impl<L, S> Handle<L, S> {
self.with_current(L::clone).ok()
}
- /// Invokes a closure with a borrowed reference to the current layer or filter,
+ /// Invokes a closure with a borrowed reference to the current layer,
/// returning the result (or an error if the subscriber no longer exists).
pub fn with_current<T>(&self, f: impl FnOnce(&L) -> T) -> Result<T, Error> {
let inner = self.inner.upgrade().ok_or(Error {