From 8919fa0ee1de860942dd47c1120bcfbc01472515 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Mon, 28 Nov 2022 16:57:03 -0800 Subject: [PATCH 1/9] Fully implement Filter for Box Pass all the Filter methods through to the underlying Box/Arc Filter rather than relying on default implementations. --- .../src/filter/subscriber_filters/mod.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tracing-subscriber/src/filter/subscriber_filters/mod.rs b/tracing-subscriber/src/filter/subscriber_filters/mod.rs index c7837ec927..c6022ee090 100644 --- a/tracing-subscriber/src/filter/subscriber_filters/mod.rs +++ b/tracing-subscriber/src/filter/subscriber_filters/mod.rs @@ -478,6 +478,36 @@ macro_rules! filter_impl_body { fn max_level_hint(&self) -> Option { self.deref().max_level_hint() } + + #[inline] + fn event_enabled(&self, event: &Event<'_>, cx: &Context<'_, S>) -> bool { + self.deref().event_enabled(event, cx) + } + + #[inline] + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { + self.deref().on_new_span(attrs, id, ctx) + } + + #[inline] + fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) { + self.deref().on_record(id, values, ctx) + } + + #[inline] + fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) { + self.deref().on_enter(id, ctx) + } + + #[inline] + fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) { + self.deref().on_exit(id, ctx) + } + + #[inline] + fn on_close(&self, id: span::Id, ctx: Context<'_, S>) { + self.deref().on_close(id, ctx) + } }; } From 00e304b1ba5d117452ddd69df6bf127bedf03bff Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Mon, 28 Nov 2022 17:07:07 -0800 Subject: [PATCH 2/9] Implement Filter for Option Where None means "no filtering". --- .../src/filter/subscriber_filters/mod.rs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tracing-subscriber/src/filter/subscriber_filters/mod.rs b/tracing-subscriber/src/filter/subscriber_filters/mod.rs index c6022ee090..be8ba59000 100644 --- a/tracing-subscriber/src/filter/subscriber_filters/mod.rs +++ b/tracing-subscriber/src/filter/subscriber_filters/mod.rs @@ -523,6 +523,75 @@ impl subscribe::Filter for Box + Send + Sync + 's filter_impl_body!(); } +// Implement Filter for Option where None => allow +#[cfg(feature = "registry")] +#[cfg_attr(docsrs, doc(cfg(feature = "registry")))] +impl subscribe::Filter for Option +where + F: subscribe::Filter, +{ + #[inline] + fn enabled(&self, meta: &Metadata<'_>, ctx: &Context<'_, S>) -> bool { + self.as_ref() + .map(|inner| inner.enabled(meta, ctx)) + .unwrap_or(true) + } + + #[inline] + fn callsite_enabled(&self, meta: &'static Metadata<'static>) -> Interest { + self.as_ref() + .map(|inner| inner.callsite_enabled(meta)) + .unwrap_or_else(Interest::sometimes) + } + + #[inline] + fn max_level_hint(&self) -> Option { + self.as_ref().and_then(|inner| inner.max_level_hint()) + } + + #[inline] + fn event_enabled(&self, event: &Event<'_>, ctx: &Context<'_, S>) -> bool { + self.as_ref() + .map(|inner| inner.event_enabled(event, ctx)) + .unwrap_or(true) + } + + #[inline] + fn on_new_span(&self, attrs: &span::Attributes<'_>, id: &span::Id, ctx: Context<'_, S>) { + if let Some(inner) = self { + inner.on_new_span(attrs, id, ctx) + } + } + + #[inline] + fn on_record(&self, id: &span::Id, values: &span::Record<'_>, ctx: Context<'_, S>) { + if let Some(inner) = self { + inner.on_record(id, values, ctx) + } + } + + #[inline] + fn on_enter(&self, id: &span::Id, ctx: Context<'_, S>) { + if let Some(inner) = self { + inner.on_enter(id, ctx) + } + } + + #[inline] + fn on_exit(&self, id: &span::Id, ctx: Context<'_, S>) { + if let Some(inner) = self { + inner.on_exit(id, ctx) + } + } + + #[inline] + fn on_close(&self, id: span::Id, ctx: Context<'_, S>) { + if let Some(inner) = self { + inner.on_close(id, ctx) + } + } +} + // === impl Filtered === impl Filtered { From 55403216b18f46f370a92345656120b881e15860 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Wed, 7 Dec 2022 11:59:43 -0800 Subject: [PATCH 3/9] Add test for Option on subscribers Make sure None lets everything through. --- .../tests/subscriber_filters/main.rs | 1 + .../tests/subscriber_filters/option.rs | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 tracing-subscriber/tests/subscriber_filters/option.rs diff --git a/tracing-subscriber/tests/subscriber_filters/main.rs b/tracing-subscriber/tests/subscriber_filters/main.rs index 0ec43b67e1..79aacbfca2 100644 --- a/tracing-subscriber/tests/subscriber_filters/main.rs +++ b/tracing-subscriber/tests/subscriber_filters/main.rs @@ -1,5 +1,6 @@ #![cfg(feature = "registry")] mod filter_scopes; +mod option; mod per_event; mod targets; mod trees; diff --git a/tracing-subscriber/tests/subscriber_filters/option.rs b/tracing-subscriber/tests/subscriber_filters/option.rs new file mode 100644 index 0000000000..0dc8dbf579 --- /dev/null +++ b/tracing-subscriber/tests/subscriber_filters/option.rs @@ -0,0 +1,40 @@ +use super::*; +use tracing_subscriber::{filter, prelude::*, Subscribe}; + +fn filter() -> filter::DynFilterFn { + // Use dynamic filter fn to disable interest caching and max-level hints, + // allowing us to put all of these tests in the same file. + filter::dynamic_filter_fn(|_, _| false) +} + +#[test] +fn option_some() { + let (subscribe, handle) = subscriber::mock().only().run_with_handle(); + let subscribe = Box::new(subscribe.with_filter(Some(filter()))); + + let _guard = tracing_subscriber::registry().with(subscribe).set_default(); + + for i in 0..2 { + tracing::info!(i); + } + + handle.assert_finished(); +} + +#[test] +fn option_none() { + let (subscribe, handle) = subscriber::mock() + .event(expect::event()) + .event(expect::event()) + .only() + .run_with_handle(); + let subscribe = Box::new(subscribe.with_filter(None::>)); + + let _guard = tracing_subscriber::registry().with(subscribe).set_default(); + + for i in 0..2 { + tracing::info!(i); + } + + handle.assert_finished(); +} From 38f541668ce8dc68b45d910258a1faf2423636c3 Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Wed, 7 Dec 2022 16:08:47 -0800 Subject: [PATCH 4/9] Add documentation for Option --- tracing-subscriber/src/subscribe/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tracing-subscriber/src/subscribe/mod.rs b/tracing-subscriber/src/subscribe/mod.rs index a18d95fc5a..bab01f869a 100644 --- a/tracing-subscriber/src/subscribe/mod.rs +++ b/tracing-subscriber/src/subscribe/mod.rs @@ -464,11 +464,13 @@ //! //! This crate's [`filter`] module provides a number of types which implement //! the [`Filter`] trait, such as [`LevelFilter`], [`Targets`], and -//! [`FilterFn`]. These [`Filter`]s provide ready-made implementations of -//! common forms of filtering. For custom filtering policies, the [`FilterFn`] -//! and [`DynFilterFn`] types allow implementing a [`Filter`] with a closure or +//! [`FilterFn`]. These [`Filter`]s provide ready-made implementations of common +//! forms of filtering. For custom filtering policies, the [`FilterFn`] and +//! [`DynFilterFn`] types allow implementing a [`Filter`] with a closure or //! function pointer. In addition, when more control is required, the [`Filter`] -//! trait may also be implemented for user-defined types. +//! trait may also be implemented for user-defined types. [`Option`] +//! also implements [`Filter`], to allow for a (surprise!) optional filter - +//! [`None`](Option::None) filters nothing (that is, allows everything through). //! //!
//!

From 74f94ee45cc7e463563f2f53c6e6b76255b4ef10 Mon Sep 17 00:00:00 2001
From: Jeremy Fitzhardinge 
Date: Tue, 13 Dec 2022 09:30:34 -0800
Subject: [PATCH 5/9] review comment fixes

---
 tracing-subscriber/src/subscribe/mod.rs               | 5 +++--
 tracing-subscriber/tests/subscriber_filters/option.rs | 4 ++--
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/tracing-subscriber/src/subscribe/mod.rs b/tracing-subscriber/src/subscribe/mod.rs
index bab01f869a..c7ffa8d083 100644
--- a/tracing-subscriber/src/subscribe/mod.rs
+++ b/tracing-subscriber/src/subscribe/mod.rs
@@ -469,8 +469,9 @@
 //! [`DynFilterFn`] types allow implementing a [`Filter`] with a closure or
 //! function pointer. In addition, when more control is required, the [`Filter`]
 //! trait may also be implemented for user-defined types. [`Option`]
-//! also implements [`Filter`], to allow for a (surprise!) optional filter -
-//! [`None`](Option::None) filters nothing (that is, allows everything through).
+//! also implements [`Filter`], which allows for an optional filter where
+//! [`None`](Option::None) filters out _nothing_ (that is, allows everything
+//! through).
 //!
 //! 
//!
diff --git a/tracing-subscriber/tests/subscriber_filters/option.rs b/tracing-subscriber/tests/subscriber_filters/option.rs
index 0dc8dbf579..9541ebf50c 100644
--- a/tracing-subscriber/tests/subscriber_filters/option.rs
+++ b/tracing-subscriber/tests/subscriber_filters/option.rs
@@ -1,7 +1,7 @@
 use super::*;
 use tracing_subscriber::{filter, prelude::*, Subscribe};
 
-fn filter() -> filter::DynFilterFn {
+fn filter_out_everything() -> filter::DynFilterFn {
     // Use dynamic filter fn to disable interest caching and max-level hints,
     // allowing us to put all of these tests in the same file.
     filter::dynamic_filter_fn(|_, _| false)
@@ -10,7 +10,7 @@ fn filter() -> filter::DynFilterFn {
 #[test]
 fn option_some() {
     let (subscribe, handle) = subscriber::mock().only().run_with_handle();
-    let subscribe = Box::new(subscribe.with_filter(Some(filter())));
+    let subscribe = subscribe.with_filter(Some(filter_out_everything()));
 
     let _guard = tracing_subscriber::registry().with(subscribe).set_default();
 

From b447e1757c7d520edac13d4a5def0eeae9ea9556 Mon Sep 17 00:00:00 2001
From: Jeremy Fitzhardinge 
Date: Tue, 13 Dec 2022 18:11:37 -0800
Subject: [PATCH 6/9] address more review comments

---
 tracing-subscriber/src/subscribe/mod.rs       | 23 +++++++++++++++----
 .../tests/subscriber_filters/option.rs        | 22 +++++++++++++++++-
 2 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/tracing-subscriber/src/subscribe/mod.rs b/tracing-subscriber/src/subscribe/mod.rs
index c7ffa8d083..d28b63ca03 100644
--- a/tracing-subscriber/src/subscribe/mod.rs
+++ b/tracing-subscriber/src/subscribe/mod.rs
@@ -468,10 +468,25 @@
 //! forms of filtering. For custom filtering policies, the [`FilterFn`] and
 //! [`DynFilterFn`] types allow implementing a [`Filter`] with a closure or
 //! function pointer. In addition, when more control is required, the [`Filter`]
-//! trait may also be implemented for user-defined types. [`Option`]
-//! also implements [`Filter`], which allows for an optional filter where
-//! [`None`](Option::None) filters out _nothing_ (that is, allows everything
-//! through).
+//! trait may also be implemented for user-defined types.
+//!
+//! [`Option`] also implements [`Filter`], which allows for an optional
+//! filter. [`None`](Option::None) filters out _nothing_ (that is, allows
+//! everything through). For example:
+//!
+//! ```rust
+//! # use tracing_subscriber::{filter::filter_fn, Subscribe};
+//! # use tracing_core::{Metadata, collect::Collect};
+//! # struct MySubscriber(std::marker::PhantomData);
+//! # impl MySubscriber { fn new() -> Self { Self(std::marker::PhantomData)} }
+//! # impl Subscribe for MySubscriber {}
+//! # fn my_filter(_: &str) -> impl Fn(&Metadata) -> bool { |_| true  }
+//! fn setup_tracing(filter_config: Option<&str>) {
+//!     let layer = MySubscriber::::new()
+//!         .with_filter(filter_config.map(|config| filter_fn(my_filter(config))));
+//! //...
+//! }
+//! ```
 //!
 //! 
//!
diff --git a/tracing-subscriber/tests/subscriber_filters/option.rs b/tracing-subscriber/tests/subscriber_filters/option.rs
index 9541ebf50c..92df19bab8 100644
--- a/tracing-subscriber/tests/subscriber_filters/option.rs
+++ b/tracing-subscriber/tests/subscriber_filters/option.rs
@@ -28,7 +28,7 @@ fn option_none() {
         .event(expect::event())
         .only()
         .run_with_handle();
-    let subscribe = Box::new(subscribe.with_filter(None::>));
+    let subscribe = subscribe.with_filter(None::>);
 
     let _guard = tracing_subscriber::registry().with(subscribe).set_default();
 
@@ -38,3 +38,23 @@ fn option_none() {
 
     handle.assert_finished();
 }
+
+#[test]
+fn option_mixed() {
+    let (subscribe, handle) = subscriber::mock()
+        .event(expect::event())
+        .only()
+        .run_with_handle();
+    let subscribe = subscribe
+        .with_filter(filter::dynamic_filter_fn(|meta, _ctx| {
+            meta.target() == "interesting"
+        }))
+        .with_filter(None::>);
+
+    let _guard = tracing_subscriber::registry().with(subscribe).set_default();
+
+    tracing::info!(target: "interesting", x="foo");
+    tracing::info!(target: "boring", x="bar");
+
+    handle.assert_finished();
+}

From 7a6bb31bce19c82b30c2a249ad61a9b4d9907268 Mon Sep 17 00:00:00 2001
From: Ryan Johnson 
Date: Mon, 27 Mar 2023 09:27:31 -0700
Subject: [PATCH 7/9] Add tests and tweak `None` filter interest level

* Added tests for max level filtering and interest caching with
multiple subscribers.
* Changed the interest level for a `None` filter from `sometimes`
to `always` so other filters can be cached more effectively.
---
 .../src/filter/subscriber_filters/mod.rs      |  2 +-
 .../tests/option_filter_interest_caching.rs   | 52 +++++++++++
 .../tests/subscriber_filters/option.rs        | 86 ++++++++++++++++++-
 3 files changed, 138 insertions(+), 2 deletions(-)
 create mode 100644 tracing-subscriber/tests/option_filter_interest_caching.rs

diff --git a/tracing-subscriber/src/filter/subscriber_filters/mod.rs b/tracing-subscriber/src/filter/subscriber_filters/mod.rs
index be8ba59000..d519aa4d7c 100644
--- a/tracing-subscriber/src/filter/subscriber_filters/mod.rs
+++ b/tracing-subscriber/src/filter/subscriber_filters/mod.rs
@@ -541,7 +541,7 @@ where
     fn callsite_enabled(&self, meta: &'static Metadata<'static>) -> Interest {
         self.as_ref()
             .map(|inner| inner.callsite_enabled(meta))
-            .unwrap_or_else(Interest::sometimes)
+            .unwrap_or_else(Interest::always)
     }
 
     #[inline]
diff --git a/tracing-subscriber/tests/option_filter_interest_caching.rs b/tracing-subscriber/tests/option_filter_interest_caching.rs
new file mode 100644
index 0000000000..69c0d9fc94
--- /dev/null
+++ b/tracing-subscriber/tests/option_filter_interest_caching.rs
@@ -0,0 +1,52 @@
+// A separate test crate for `Option` for isolation from other tests
+// that may influence the interest cache.
+
+use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};
+use tracing_mock::{subscriber, expect};
+use tracing_subscriber::{filter, prelude::*, Subscribe};
+
+/// A `None` filter should always be interested in events, and it should not
+/// needlessly degrade the caching of other filters.
+#[test]
+fn none_interest_cache() {
+    let (subscribe_none, handle_none) = subscriber::mock()
+        .event(expect::event())
+        .event(expect::event())
+        .only()
+        .run_with_handle();
+    let subscribe_none = subscribe_none
+        .with_filter(None::>);
+
+    let times_filtered = Arc::new(AtomicUsize::new(0));
+    let (subscribe_filter_fn, handle_filter_fn) = subscriber::mock()
+        .event(expect::event())
+        .event(expect::event())
+        .only()
+        .run_with_handle();
+    let subscribe_filter_fn = subscribe_filter_fn
+        .with_filter(filter::filter_fn({
+            let times_filtered = Arc::clone(×_filtered);
+            move |_| {
+                times_filtered.fetch_add(1, Ordering::Relaxed);
+                true
+            }
+        }));
+
+    let subscriber = tracing_subscriber::registry()
+        .with(subscribe_none)
+        .with(subscribe_filter_fn);
+
+    let _guard = subscriber.set_default();
+    for _ in 0..2 {
+        tracing::debug!(target: "always_interesting", x="bar");
+    }
+
+    // The `None` filter is unchanging and performs no filtering, so it should
+    // be cacheable and always be interested in events. The filter fn is a
+    // non-dynamic filter fn, which means the result can be cached per callsite.
+    // The filter fn should only need to be called once, and the `Option` filter
+    // should not interfere in the caching of that result.
+    assert_eq!(times_filtered.load(Ordering::Relaxed), 1);
+    handle_none.assert_finished();
+    handle_filter_fn.assert_finished();
+}
diff --git a/tracing-subscriber/tests/subscriber_filters/option.rs b/tracing-subscriber/tests/subscriber_filters/option.rs
index 92df19bab8..52ea902179 100644
--- a/tracing-subscriber/tests/subscriber_filters/option.rs
+++ b/tracing-subscriber/tests/subscriber_filters/option.rs
@@ -1,5 +1,6 @@
 use super::*;
-use tracing_subscriber::{filter, prelude::*, Subscribe};
+use tracing::Collect;
+use tracing_subscriber::{filter::{self, LevelFilter}, prelude::*, Subscribe};
 
 fn filter_out_everything() -> filter::DynFilterFn {
     // Use dynamic filter fn to disable interest caching and max-level hints,
@@ -58,3 +59,86 @@ fn option_mixed() {
 
     handle.assert_finished();
 }
+
+/// The lack of a max level hint from a `None` filter should result in no max
+/// level hint when combined with other filters/subscribers.
+#[test]
+fn none_max_level_hint() {
+    let (subscribe_none, handle_none) = subscriber::mock()
+        .event(expect::event())
+        .event(expect::event())
+        .only()
+        .run_with_handle();
+    let subscribe_none = subscribe_none
+        .with_filter(None::>);
+    assert!(subscribe_none.max_level_hint().is_none());
+
+    let (subscribe_filter_fn, handle_filter_fn) = subscriber::mock()
+        .event(expect::event())
+        .only()
+        .run_with_handle();
+    let max_level = Level::INFO;
+    let subscribe_filter_fn = subscribe_filter_fn
+        .with_filter(filter::dynamic_filter_fn(move |meta, _| {
+            return meta.level() <= &max_level
+        })
+        .with_max_level_hint(max_level));
+    assert_eq!(subscribe_filter_fn.max_level_hint(), Some(LevelFilter::INFO));
+
+    let subscriber = tracing_subscriber::registry()
+        .with(subscribe_none)
+        .with(subscribe_filter_fn);
+    // The absence of a hint from the `None` filter upgrades the `INFO` hint
+    // from the filter fn subscriber.
+    assert!(subscriber.max_level_hint().is_none());
+
+    let _guard = subscriber.set_default();
+    tracing::info!(target: "interesting", x="foo");
+    tracing::debug!(target: "sometimes_interesting", x="bar");
+
+    handle_none.assert_finished();
+    handle_filter_fn.assert_finished();
+}
+
+/// The max level hint from inside a `Some(filter)` filter should be propagated
+/// and combined with other filters/subscribers.
+#[test]
+fn some_max_level_hint() {
+    let (subscribe_some, handle_some) = subscriber::mock()
+        .event(expect::event())
+        .event(expect::event())
+        .only()
+        .run_with_handle();
+    let subscribe_some = subscribe_some
+        .with_filter(Some(
+            filter::dynamic_filter_fn(move |meta, _| {
+                return meta.level() <= &Level::DEBUG
+            }).with_max_level_hint(Level::DEBUG)
+        ));
+    assert_eq!(subscribe_some.max_level_hint(), Some(LevelFilter::DEBUG));
+
+    let (subscribe_filter_fn, handle_filter_fn) = subscriber::mock()
+        .event(expect::event())
+        .only()
+        .run_with_handle();
+    let subscribe_filter_fn = subscribe_filter_fn
+        .with_filter(filter::dynamic_filter_fn(move |meta, _| {
+            return meta.level() <= &Level::INFO
+        })
+        .with_max_level_hint(Level::INFO));
+    assert_eq!(subscribe_filter_fn.max_level_hint(), Some(LevelFilter::INFO));
+
+    let subscriber = tracing_subscriber::registry()
+        .with(subscribe_some)
+        .with(subscribe_filter_fn);
+    // The `DEBUG` hint from the `Some` filter upgrades the `INFO` hint from the
+    // filter fn subscriber.
+    assert_eq!(subscriber.max_level_hint(), Some(LevelFilter::DEBUG));
+
+    let _guard = subscriber.set_default();
+    tracing::info!(target: "interesting", x="foo");
+    tracing::debug!(target: "sometimes_interesting", x="bar");
+
+    handle_some.assert_finished();
+    handle_filter_fn.assert_finished();
+}

From 59cba8cd140ad7b714e26bf46ca3d81d769ac4d2 Mon Sep 17 00:00:00 2001
From: Jeremy Fitzhardinge 
Date: Sun, 30 Apr 2023 23:48:43 -0700
Subject: [PATCH 8/9] Run cargo fmt

---
 .../tests/option_filter_interest_caching.rs   | 25 +++++-----
 .../tests/subscriber_filters/option.rs        | 47 ++++++++++---------
 2 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/tracing-subscriber/tests/option_filter_interest_caching.rs b/tracing-subscriber/tests/option_filter_interest_caching.rs
index 69c0d9fc94..5853d65718 100644
--- a/tracing-subscriber/tests/option_filter_interest_caching.rs
+++ b/tracing-subscriber/tests/option_filter_interest_caching.rs
@@ -1,8 +1,11 @@
 // A separate test crate for `Option` for isolation from other tests
 // that may influence the interest cache.
 
-use std::sync::{Arc, atomic::{AtomicUsize, Ordering}};
-use tracing_mock::{subscriber, expect};
+use std::sync::{
+    atomic::{AtomicUsize, Ordering},
+    Arc,
+};
+use tracing_mock::{expect, subscriber};
 use tracing_subscriber::{filter, prelude::*, Subscribe};
 
 /// A `None` filter should always be interested in events, and it should not
@@ -14,8 +17,7 @@ fn none_interest_cache() {
         .event(expect::event())
         .only()
         .run_with_handle();
-    let subscribe_none = subscribe_none
-        .with_filter(None::>);
+    let subscribe_none = subscribe_none.with_filter(None::>);
 
     let times_filtered = Arc::new(AtomicUsize::new(0));
     let (subscribe_filter_fn, handle_filter_fn) = subscriber::mock()
@@ -23,14 +25,13 @@ fn none_interest_cache() {
         .event(expect::event())
         .only()
         .run_with_handle();
-    let subscribe_filter_fn = subscribe_filter_fn
-        .with_filter(filter::filter_fn({
-            let times_filtered = Arc::clone(×_filtered);
-            move |_| {
-                times_filtered.fetch_add(1, Ordering::Relaxed);
-                true
-            }
-        }));
+    let subscribe_filter_fn = subscribe_filter_fn.with_filter(filter::filter_fn({
+        let times_filtered = Arc::clone(×_filtered);
+        move |_| {
+            times_filtered.fetch_add(1, Ordering::Relaxed);
+            true
+        }
+    }));
 
     let subscriber = tracing_subscriber::registry()
         .with(subscribe_none)
diff --git a/tracing-subscriber/tests/subscriber_filters/option.rs b/tracing-subscriber/tests/subscriber_filters/option.rs
index 52ea902179..0bdf356d33 100644
--- a/tracing-subscriber/tests/subscriber_filters/option.rs
+++ b/tracing-subscriber/tests/subscriber_filters/option.rs
@@ -1,6 +1,10 @@
 use super::*;
 use tracing::Collect;
-use tracing_subscriber::{filter::{self, LevelFilter}, prelude::*, Subscribe};
+use tracing_subscriber::{
+    filter::{self, LevelFilter},
+    prelude::*,
+    Subscribe,
+};
 
 fn filter_out_everything() -> filter::DynFilterFn {
     // Use dynamic filter fn to disable interest caching and max-level hints,
@@ -69,8 +73,7 @@ fn none_max_level_hint() {
         .event(expect::event())
         .only()
         .run_with_handle();
-    let subscribe_none = subscribe_none
-        .with_filter(None::>);
+    let subscribe_none = subscribe_none.with_filter(None::>);
     assert!(subscribe_none.max_level_hint().is_none());
 
     let (subscribe_filter_fn, handle_filter_fn) = subscriber::mock()
@@ -78,12 +81,14 @@ fn none_max_level_hint() {
         .only()
         .run_with_handle();
     let max_level = Level::INFO;
-    let subscribe_filter_fn = subscribe_filter_fn
-        .with_filter(filter::dynamic_filter_fn(move |meta, _| {
-            return meta.level() <= &max_level
-        })
-        .with_max_level_hint(max_level));
-    assert_eq!(subscribe_filter_fn.max_level_hint(), Some(LevelFilter::INFO));
+    let subscribe_filter_fn = subscribe_filter_fn.with_filter(
+        filter::dynamic_filter_fn(move |meta, _| return meta.level() <= &max_level)
+            .with_max_level_hint(max_level),
+    );
+    assert_eq!(
+        subscribe_filter_fn.max_level_hint(),
+        Some(LevelFilter::INFO)
+    );
 
     let subscriber = tracing_subscriber::registry()
         .with(subscribe_none)
@@ -109,24 +114,24 @@ fn some_max_level_hint() {
         .event(expect::event())
         .only()
         .run_with_handle();
-    let subscribe_some = subscribe_some
-        .with_filter(Some(
-            filter::dynamic_filter_fn(move |meta, _| {
-                return meta.level() <= &Level::DEBUG
-            }).with_max_level_hint(Level::DEBUG)
-        ));
+    let subscribe_some = subscribe_some.with_filter(Some(
+        filter::dynamic_filter_fn(move |meta, _| return meta.level() <= &Level::DEBUG)
+            .with_max_level_hint(Level::DEBUG),
+    ));
     assert_eq!(subscribe_some.max_level_hint(), Some(LevelFilter::DEBUG));
 
     let (subscribe_filter_fn, handle_filter_fn) = subscriber::mock()
         .event(expect::event())
         .only()
         .run_with_handle();
-    let subscribe_filter_fn = subscribe_filter_fn
-        .with_filter(filter::dynamic_filter_fn(move |meta, _| {
-            return meta.level() <= &Level::INFO
-        })
-        .with_max_level_hint(Level::INFO));
-    assert_eq!(subscribe_filter_fn.max_level_hint(), Some(LevelFilter::INFO));
+    let subscribe_filter_fn = subscribe_filter_fn.with_filter(
+        filter::dynamic_filter_fn(move |meta, _| return meta.level() <= &Level::INFO)
+            .with_max_level_hint(Level::INFO),
+    );
+    assert_eq!(
+        subscribe_filter_fn.max_level_hint(),
+        Some(LevelFilter::INFO)
+    );
 
     let subscriber = tracing_subscriber::registry()
         .with(subscribe_some)

From 883c594946d15403c50fc13bf45e48f766fc1976 Mon Sep 17 00:00:00 2001
From: Jeremy Fitzhardinge 
Date: Wed, 26 Jul 2023 19:45:08 -0700
Subject: [PATCH 9/9] Fix clippy warning

---
 tracing-subscriber/src/fmt/time/mod.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tracing-subscriber/src/fmt/time/mod.rs b/tracing-subscriber/src/fmt/time/mod.rs
index fd77b2c750..21d692bbb0 100644
--- a/tracing-subscriber/src/fmt/time/mod.rs
+++ b/tracing-subscriber/src/fmt/time/mod.rs
@@ -48,7 +48,7 @@ pub trait FormatTime {
 /// # }
 /// ```
 pub fn time() -> SystemTime {
-    SystemTime::default()
+    SystemTime
 }
 
 /// Returns a new `Uptime` timestamp provider.