diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:13:23 +0000 |
commit | 20431706a863f92cb37dc512fef6e48d192aaf2c (patch) | |
tree | 2867f13f5fd5437ba628c67d7f87309ccadcd286 /vendor/tracing-subscriber-0.3.3/src/fmt/fmt_layer.rs | |
parent | Releasing progress-linux version 1.65.0+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.tar.xz rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.zip |
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | vendor/tracing-subscriber-0.3.3/src/fmt/fmt_layer.rs (renamed from vendor/tracing-subscriber/src/fmt/fmt_layer.rs) | 215 |
1 files changed, 26 insertions, 189 deletions
diff --git a/vendor/tracing-subscriber/src/fmt/fmt_layer.rs b/vendor/tracing-subscriber-0.3.3/src/fmt/fmt_layer.rs index 21992e780..0e0d5e0eb 100644 --- a/vendor/tracing-subscriber/src/fmt/fmt_layer.rs +++ b/vendor/tracing-subscriber-0.3.3/src/fmt/fmt_layer.rs @@ -56,7 +56,7 @@ use tracing_core::{ /// # tracing::subscriber::set_global_default(subscriber).unwrap(); /// ``` /// -/// [`Layer`]: super::layer::Layer +/// [`Layer`]: ../layer/trait.Layer.html #[cfg_attr(docsrs, doc(cfg(all(feature = "fmt", feature = "std"))))] #[derive(Debug)] pub struct Layer< @@ -70,11 +70,11 @@ pub struct Layer< fmt_event: E, fmt_span: format::FmtSpanConfig, is_ansi: bool, - _inner: PhantomData<fn(S)>, + _inner: PhantomData<S>, } impl<S> Layer<S> { - /// Returns a new [`Layer`][self::Layer] with the default configuration. + /// Returns a new [`Layer`](struct.Layer.html) with the default configuration. pub fn new() -> Self { Self::default() } @@ -87,8 +87,8 @@ where N: for<'writer> FormatFields<'writer> + 'static, W: for<'writer> MakeWriter<'writer> + 'static, { - /// Sets the [event formatter][`FormatEvent`] that the layer being built will - /// use to format events. + /// Sets the [event formatter][`FormatEvent`] that the layer will use to + /// format events. /// /// The event formatter may be any type implementing the [`FormatEvent`] /// trait, which is implemented for all functions taking a [`FmtContext`], a @@ -108,7 +108,7 @@ where /// ``` /// [`FormatEvent`]: format::FormatEvent /// [`Event`]: tracing::Event - /// [`Writer`]: format::Writer + /// [`Writer`]: crate::format::Writer pub fn event_format<E2>(self, e: E2) -> Layer<S, N, E2, W> where E2: FormatEvent<S, N> + 'static, @@ -122,40 +122,11 @@ where _inner: self._inner, } } - - /// Updates the event formatter by applying a function to the existing event formatter. - /// - /// This sets the event formatter that the layer being built will use to record fields. - /// - /// # Examples - /// - /// Updating an event formatter: - /// - /// ```rust - /// let layer = tracing_subscriber::fmt::layer() - /// .map_event_format(|e| e.compact()); - /// # // this is necessary for type inference. - /// # use tracing_subscriber::Layer as _; - /// # let _ = layer.with_subscriber(tracing_subscriber::registry::Registry::default()); - /// ``` - pub fn map_event_format<E2>(self, f: impl FnOnce(E) -> E2) -> Layer<S, N, E2, W> - where - E2: FormatEvent<S, N> + 'static, - { - Layer { - fmt_fields: self.fmt_fields, - fmt_event: f(self.fmt_event), - fmt_span: self.fmt_span, - make_writer: self.make_writer, - is_ansi: self.is_ansi, - _inner: self._inner, - } - } } // This needs to be a seperate impl block because they place different bounds on the type parameters. impl<S, N, E, W> Layer<S, N, E, W> { - /// Sets the [`MakeWriter`] that the layer being built will use to write events. + /// Sets the [`MakeWriter`] that the [`Layer`] being built will use to write events. /// /// # Examples /// @@ -171,6 +142,9 @@ impl<S, N, E, W> Layer<S, N, E, W> { /// # use tracing_subscriber::Layer as _; /// # let _ = layer.with_subscriber(tracing_subscriber::registry::Registry::default()); /// ``` + /// + /// [`MakeWriter`]: ../fmt/trait.MakeWriter.html + /// [`Layer`]: ../layer/trait.Layer.html pub fn with_writer<W2>(self, make_writer: W2) -> Layer<S, N, E, W2> where W2: for<'writer> MakeWriter<'writer> + 'static, @@ -185,57 +159,7 @@ impl<S, N, E, W> Layer<S, N, E, W> { } } - /// Borrows the [writer] for this [`Layer`]. - /// - /// [writer]: MakeWriter - pub fn writer(&self) -> &W { - &self.make_writer - } - - /// Mutably borrows the [writer] for this [`Layer`]. - /// - /// This method is primarily expected to be used with the - /// [`reload::Handle::modify`](crate::reload::Handle::modify) method. - /// - /// # Examples - /// - /// ``` - /// # use tracing::info; - /// # use tracing_subscriber::{fmt,reload,Registry,prelude::*}; - /// # fn non_blocking<T: std::io::Write>(writer: T) -> (fn() -> std::io::Stdout) { - /// # std::io::stdout - /// # } - /// # fn main() { - /// let layer = fmt::layer().with_writer(non_blocking(std::io::stderr())); - /// let (layer, reload_handle) = reload::Layer::new(layer); - /// # - /// # // specifying the Registry type is required - /// # let _: &reload::Handle<fmt::Layer<Registry, _, _, _>, Registry> = &reload_handle; - /// # - /// info!("This will be logged to stderr"); - /// reload_handle.modify(|layer| *layer.writer_mut() = non_blocking(std::io::stdout())); - /// info!("This will be logged to stdout"); - /// # } - /// ``` - /// - /// [writer]: MakeWriter - pub fn writer_mut(&mut self) -> &mut W { - &mut self.make_writer - } - - /// Sets whether this layer should use ANSI terminal formatting - /// escape codes (such as colors). - /// - /// This method is primarily expected to be used with the - /// [`reload::Handle::modify`](crate::reload::Handle::modify) method when changing - /// the writer. - #[cfg(feature = "ansi")] - #[cfg_attr(docsrs, doc(cfg(feature = "ansi")))] - pub fn set_ansi(&mut self, ansi: bool) { - self.is_ansi = ansi; - } - - /// Configures the layer to support [`libtest`'s output capturing][capturing] when used in + /// Configures the subscriber to support [`libtest`'s output capturing][capturing] when used in /// unit tests. /// /// See [`TestWriter`] for additional details. @@ -256,7 +180,7 @@ impl<S, N, E, W> Layer<S, N, E, W> { /// ``` /// [capturing]: /// https://doc.rust-lang.org/book/ch11-02-running-tests.html#showing-function-output - /// [`TestWriter`]: super::writer::TestWriter + /// [`TestWriter`]: writer/struct.TestWriter.html pub fn with_test_writer(self) -> Layer<S, N, E, TestWriter> { Layer { fmt_fields: self.fmt_fields, @@ -277,39 +201,6 @@ impl<S, N, E, W> Layer<S, N, E, W> { ..self } } - - /// Updates the [`MakeWriter`] by applying a function to the existing [`MakeWriter`]. - /// - /// This sets the [`MakeWriter`] that the layer being built will use to write events. - /// - /// # Examples - /// - /// Redirect output to stderr if level is <= WARN: - /// - /// ```rust - /// use tracing::Level; - /// use tracing_subscriber::fmt::{self, writer::MakeWriterExt}; - /// - /// let stderr = std::io::stderr.with_max_level(Level::WARN); - /// let layer = fmt::layer() - /// .map_writer(move |w| stderr.or_else(w)); - /// # // this is necessary for type inference. - /// # use tracing_subscriber::Layer as _; - /// # let _ = layer.with_subscriber(tracing_subscriber::registry::Registry::default()); - /// ``` - pub fn map_writer<W2>(self, f: impl FnOnce(W) -> W2) -> Layer<S, N, E, W2> - where - W2: for<'writer> MakeWriter<'writer> + 'static, - { - Layer { - fmt_fields: self.fmt_fields, - fmt_event: self.fmt_event, - fmt_span: self.fmt_span, - is_ansi: self.is_ansi, - make_writer: f(self.make_writer), - _inner: self._inner, - } - } } impl<S, N, L, T, W> Layer<S, N, format::Format<L, T>, W> @@ -393,7 +284,7 @@ where /// `Layer`s added to this subscriber. /// /// [lifecycle]: https://docs.rs/tracing/latest/tracing/span/index.html#the-span-lifecycle - /// [time]: Layer::without_time() + /// [time]: #method.without_time pub fn with_span_events(self, kind: FmtSpan) -> Self { Layer { fmt_span: self.fmt_span.with_kind(kind), @@ -408,30 +299,6 @@ where ..self } } - /// Sets whether or not an event's [source code file path][file] is - /// displayed. - /// - /// [file]: tracing_core::Metadata::file - pub fn with_file(self, display_filename: bool) -> Layer<S, N, format::Format<L, T>, W> { - Layer { - fmt_event: self.fmt_event.with_file(display_filename), - ..self - } - } - - /// Sets whether or not an event's [source code line number][line] is - /// displayed. - /// - /// [line]: tracing_core::Metadata::line - pub fn with_line_number( - self, - display_line_number: bool, - ) -> Layer<S, N, format::Format<L, T>, W> { - Layer { - fmt_event: self.fmt_event.with_line_number(display_line_number), - ..self - } - } /// Sets whether or not an event's level is displayed. pub fn with_level(self, display_level: bool) -> Layer<S, N, format::Format<L, T>, W> { @@ -442,9 +309,9 @@ where } /// Sets whether or not the [thread ID] of the current thread is displayed - /// when formatting events. + /// when formatting events /// - /// [thread ID]: std::thread::ThreadId + /// [thread ID]: https://doc.rust-lang.org/stable/std/thread/struct.ThreadId.html pub fn with_thread_ids(self, display_thread_ids: bool) -> Layer<S, N, format::Format<L, T>, W> { Layer { fmt_event: self.fmt_event.with_thread_ids(display_thread_ids), @@ -453,9 +320,9 @@ where } /// Sets whether or not the [name] of the current thread is displayed - /// when formatting events. + /// when formatting events /// - /// [name]: std::thread#naming-threads + /// [name]: https://doc.rust-lang.org/stable/std/thread/index.html#naming-threads pub fn with_thread_names( self, display_thread_names: bool, @@ -466,7 +333,7 @@ where } } - /// Sets the layer being built to use a [less verbose formatter][super::format::Compact]. + /// Sets the layer being built to use a [less verbose formatter](../fmt/format/struct.Compact.html). pub fn compact(self) -> Layer<S, N, format::Format<format::Compact, T>, W> where N: for<'writer> FormatFields<'writer> + 'static, @@ -495,7 +362,7 @@ where } } - /// Sets the layer being built to use a [JSON formatter][super::format::Json]. + /// Sets the layer being built to use a [JSON formatter](../fmt/format/struct.Json.html). /// /// The full format includes fields from all entered spans. /// @@ -510,7 +377,7 @@ where /// - [`Layer::flatten_event`] can be used to enable flattening event fields into the root /// object. /// - /// [`Layer::flatten_event`]: Layer::flatten_event() + /// [`Layer::flatten_event`]: #method.flatten_event #[cfg(feature = "json")] #[cfg_attr(docsrs, doc(cfg(feature = "json")))] pub fn json(self) -> Layer<S, format::JsonFields, format::Format<format::Json, T>, W> { @@ -531,7 +398,7 @@ where impl<S, T, W> Layer<S, format::JsonFields, format::Format<format::Json, T>, W> { /// Sets the JSON layer being built to flatten event metadata. /// - /// See [`format::Json`][super::format::Json] + /// See [`format::Json`](../fmt/format/struct.Json.html) pub fn flatten_event( self, flatten_event: bool, @@ -546,7 +413,7 @@ impl<S, T, W> Layer<S, format::JsonFields, format::Format<format::Json, T>, W> { /// Sets whether or not the formatter will include the current span in /// formatted events. /// - /// See [`format::Json`][super::format::Json] + /// See [`format::Json`](../fmt/format/struct.Json.html) pub fn with_current_span( self, display_current_span: bool, @@ -561,7 +428,7 @@ impl<S, T, W> Layer<S, format::JsonFields, format::Format<format::Json, T>, W> { /// Sets whether or not the formatter will include a list (from root to leaf) /// of all currently entered spans in formatted events. /// - /// See [`format::Json`][super::format::Json] + /// See [`format::Json`](../fmt/format/struct.Json.html) pub fn with_span_list( self, display_span_list: bool, @@ -590,36 +457,6 @@ impl<S, N, E, W> Layer<S, N, E, W> { _inner: self._inner, } } - - /// Updates the field formatter by applying a function to the existing field formatter. - /// - /// This sets the field formatter that the layer being built will use to record fields. - /// - /// # Examples - /// - /// Updating a field formatter: - /// - /// ```rust - /// use tracing_subscriber::field::MakeExt; - /// let layer = tracing_subscriber::fmt::layer() - /// .map_fmt_fields(|f| f.debug_alt()); - /// # // this is necessary for type inference. - /// # use tracing_subscriber::Layer as _; - /// # let _ = layer.with_subscriber(tracing_subscriber::registry::Registry::default()); - /// ``` - pub fn map_fmt_fields<N2>(self, f: impl FnOnce(N) -> N2) -> Layer<S, N2, E, W> - where - N2: for<'writer> FormatFields<'writer> + 'static, - { - Layer { - fmt_event: self.fmt_event, - fmt_fields: f(self.fmt_fields), - fmt_span: self.fmt_span, - make_writer: self.make_writer, - is_ansi: self.is_ansi, - _inner: self._inner, - } - } } impl<S> Default for Layer<S> { @@ -660,7 +497,7 @@ where /// formatters are in use, each can store its own formatted representation /// without conflicting. /// -/// [extensions]: crate::registry::Extensions +/// [extensions]: ../registry/struct.Extensions.html #[derive(Default)] pub struct FormattedFields<E: ?Sized> { _format_fields: PhantomData<fn(E)>, @@ -984,7 +821,7 @@ where /// If this returns `None`, then no span exists for that ID (either it has /// closed or the ID is invalid). /// - /// [stored data]: crate::registry::SpanRef + /// [stored data]: ../registry/struct.SpanRef.html #[inline] pub fn span(&self, id: &Id) -> Option<SpanRef<'_, S>> where @@ -1007,7 +844,7 @@ where /// /// If this returns `None`, then we are not currently within a span. /// - /// [stored data]: crate::registry::SpanRef + /// [stored data]: ../registry/struct.SpanRef.html #[inline] pub fn lookup_current(&self) -> Option<SpanRef<'_, S>> where |