From 7cf745c00aa5b752197f53e10571690da60a5a9c Mon Sep 17 00:00:00 2001 From: Kaifas Date: Thu, 10 Aug 2023 13:19:53 -0400 Subject: [PATCH 1/3] Make format::Writer::new() public A number of people (myself included) have expressed significant interest in having Writer::new() public for various reasons, with some difficulty getting traction. --- tracing-subscriber/src/fmt/format/mod.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tracing-subscriber/src/fmt/format/mod.rs b/tracing-subscriber/src/fmt/format/mod.rs index c9760138ab..e3edce2633 100644 --- a/tracing-subscriber/src/fmt/format/mod.rs +++ b/tracing-subscriber/src/fmt/format/mod.rs @@ -423,7 +423,12 @@ impl<'writer> Writer<'writer> { // We may not want to do that if we choose to expose specialized // constructors instead (e.g. `from_string` that stores whether the string // is empty...?) - pub(crate) fn new(writer: &'writer mut impl fmt::Write) -> Self { + //(@kaifastromai) I suppose having dedicated constructors may have certain benefits + // but I am not privy to the larger direction of tracing/subscriber. + ///Create a new [`Writer`] from any type that implements fmt::Write. + ///This can be used to e.g. obtain the raw string after this writer has formatted via a call to `[fmt::format::Format::format_event] + #[must_use] + pub fn new(writer: &'writer mut impl fmt::Write) -> Self { Self { writer: writer as &mut dyn fmt::Write, is_ansi: false, From 22739de402cc5ca41a2888c6377fe37532df28ad Mon Sep 17 00:00:00 2001 From: Cephas Storm Date: Thu, 10 Aug 2023 13:45:29 -0400 Subject: [PATCH 2/3] fix typo in doc comment --- tracing-subscriber/src/fmt/format/mod.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tracing-subscriber/src/fmt/format/mod.rs b/tracing-subscriber/src/fmt/format/mod.rs index e3edce2633..5aca128874 100644 --- a/tracing-subscriber/src/fmt/format/mod.rs +++ b/tracing-subscriber/src/fmt/format/mod.rs @@ -425,8 +425,8 @@ impl<'writer> Writer<'writer> { // is empty...?) //(@kaifastromai) I suppose having dedicated constructors may have certain benefits // but I am not privy to the larger direction of tracing/subscriber. - ///Create a new [`Writer`] from any type that implements fmt::Write. - ///This can be used to e.g. obtain the raw string after this writer has formatted via a call to `[fmt::format::Format::format_event] + ///Create a new [`Writer`] from any type that implements fmt::Write. + ///This can be used to e.g. obtain the raw string after this writer has formatted via a call to [`Format`]'s format_event. #[must_use] pub fn new(writer: &'writer mut impl fmt::Write) -> Self { Self { @@ -1072,7 +1072,12 @@ where let dimmed = writer.dimmed(); if self.display_target { - write!(writer, "{}{}", dimmed.paint(meta.target()), dimmed.paint(":"))?; + write!( + writer, + "{}{}", + dimmed.paint(meta.target()), + dimmed.paint(":") + )?; } if self.display_filename { From 336a36b8969777966ae2bfcde5e93a30038ce7f1 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Tue, 10 Oct 2023 16:51:05 -0700 Subject: [PATCH 3/3] Apply suggestions from code review --- tracing-subscriber/src/fmt/format/mod.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tracing-subscriber/src/fmt/format/mod.rs b/tracing-subscriber/src/fmt/format/mod.rs index 34bf05b166..d4c619b3fb 100644 --- a/tracing-subscriber/src/fmt/format/mod.rs +++ b/tracing-subscriber/src/fmt/format/mod.rs @@ -424,8 +424,15 @@ impl<'writer> Writer<'writer> { // is empty...?) //(@kaifastromai) I suppose having dedicated constructors may have certain benefits // but I am not privy to the larger direction of tracing/subscriber. - ///Create a new [`Writer`] from any type that implements fmt::Write. - ///This can be used to e.g. obtain the raw string after this writer has formatted via a call to [`Format`]'s format_event. + /// Create a new [`Writer`] from any type that implements [`fmt::Write`]. + /// + /// The returned `Writer` value may be passed as an argument to methods + /// such as [`Format::format_event`]. Since constructing a `Writer` + /// mutably borrows the underlying [`fmt::Write`] instance, that value may + /// be accessed again once the `Writer` is dropped. For example, if the + /// value implementing [`fmt::Write`] is a [`String`], it will contain + /// the formatted output of [`Format::format_event`], which may then be + /// used for other purposes. #[must_use] pub fn new(writer: &'writer mut impl fmt::Write) -> Self { Self {