From 2ad0055a1ca091c1eb184eb63aabea7d8a3cbf8e Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Fri, 29 Oct 2021 11:18:47 -0700 Subject: [PATCH] subscriber: fix missing `make_writer_for` in `BoxMakeWriter` ## Motivation In `tracing-subscriber` 0.3.x, `MakeWriter` filtering seems to have stopped working when using the `BoxMakeWriter` wrapper to erase the type of a `MakeWriter` implementation. It looks like what happened is that commit 6cc6c47354ceeb47da7c95faa41c6d29b71b5f37, which backported the change to add a lifetime parameter to `MakeWriter` (#781), I accidentally clobbered the `make_writer_for` method on the inner `Boxed` type, so that it only has `make_writer`: https://github.com/tokio-rs/tracing/commit/6cc6c47354ceeb47da7c95faa41c6d29b71b5f37#diff-c5dc275b15a60c1a2d4694da3797f4247c4f2e1e0978fd210dd14452d6746283L737-L739 This meant that any filtering performed by the `MakeWriter` inside the box is now ignored. My bad! ## Solution This commit puts back the missing `make_writer_for` method. Whoops! Fixes #1694 --- tracing-subscriber/src/fmt/writer.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tracing-subscriber/src/fmt/writer.rs b/tracing-subscriber/src/fmt/writer.rs index 0197479af8..0974891f71 100644 --- a/tracing-subscriber/src/fmt/writer.rs +++ b/tracing-subscriber/src/fmt/writer.rs @@ -757,10 +757,12 @@ impl fmt::Debug for BoxMakeWriter { impl<'a> MakeWriter<'a> for BoxMakeWriter { type Writer = Box; + #[inline] fn make_writer(&'a self) -> Self::Writer { self.inner.make_writer() } + #[inline] fn make_writer_for(&'a self, meta: &Metadata<'_>) -> Self::Writer { self.inner.make_writer_for(meta) } @@ -778,6 +780,11 @@ where let w = self.0.make_writer(); Box::new(w) } + + fn make_writer_for(&'a self, meta: &Metadata<'_>) -> Self::Writer { + let w = self.0.make_writer_for(meta); + Box::new(w) + } } // === impl Mutex/MutexGuardWriter ===