diff --git a/tracing-subscriber/src/filter/env/mod.rs b/tracing-subscriber/src/filter/env/mod.rs index 005851d6..a9d93793 100644 --- a/tracing-subscriber/src/filter/env/mod.rs +++ b/tracing-subscriber/src/filter/env/mod.rs @@ -204,6 +204,24 @@ pub struct EnvFilter { regex: bool, } +/// Creates an [`EnvFilter`] with the same directives as `self`. +/// +/// This does *not* clone any of the dynamic state that [`EnvFilter`] acquires while attached to a +/// subscriber. +impl Clone for EnvFilter { + fn clone(&self) -> EnvFilter { + EnvFilter { + statics: self.statics.clone(), + dynamics: self.dynamics.clone(), + has_dynamics: self.has_dynamics, + by_id: RwLock::default(), + by_cs: RwLock::default(), + scope: ThreadLocal::new(), + regex: self.regex, + } + } +} + type FieldMap = HashMap; /// Indicates that an error occurred while parsing a `EnvFilter` from an diff --git a/tracing-subscriber/src/sync.rs b/tracing-subscriber/src/sync.rs index ec42b834..be41f1b9 100644 --- a/tracing-subscriber/src/sync.rs +++ b/tracing-subscriber/src/sync.rs @@ -54,4 +54,12 @@ mod parking_lot_impl { Ok(self.inner.write()) } } + + impl Default for RwLock { + fn default() -> Self { + RwLock { + inner: parking_lot::RwLock::default(), + } + } + } }