diff --git a/tracing-subscriber/src/filter/env/mod.rs b/tracing-subscriber/src/filter/env/mod.rs index 4819e7936..af24701ae 100644 --- a/tracing-subscriber/src/filter/env/mod.rs +++ b/tracing-subscriber/src/filter/env/mod.rs @@ -204,6 +204,22 @@ 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::new(Default::default()), + by_cs: RwLock::new(Default::default()), + scope: ThreadLocal::new(), + regex: self.regex, + } + } +} + type FieldMap = HashMap; /// Indicates that an error occurred while parsing a `EnvFilter` from an