Lines Matching full:subscriber
1 //! A `Subscriber` for formatting and logging `tracing` data.
7 //! implementation of the [`Subscriber`] trait that records `tracing`'s `Event`s
16 //! tracing-subscriber = "0.3"
23 //! Add the following to your executable to initialize the default subscriber:
32 //! The default subscriber installed by `init` enables you to filter events
48 //! You can configure a subscriber instead of using the defaults with
51 //! ### Subscriber
57 //! let subscriber = tracing_subscriber::fmt()
67 //! The output format used by the layer and subscriber in this module is
119 //! // Create a `fmt` subscriber that uses our custom event format, and set it
146 //! ### Using Your Subscriber
148 //! Finally, once you have configured your `Subscriber`, you need to
151 //! A subscriber can be installed globally using:
156 //! let subscriber = FmtSubscriber::new();
158 //! tracing::subscriber::set_global_default(subscriber)
159 //! .map_err(|_err| eprintln!("Unable to set global default subscriber"));
161 //! // subscriber multiple times
187 //! [`FmtSubscriber`]: Subscriber
188 //! [`Subscriber`]:
189 //! https://docs.rs/tracing/latest/tracing/trait.Subscriber.html
193 use tracing_core::{span, subscriber::Interest, Event, Metadata};
220 /// A `Subscriber` that logs formatted representations of `tracing` events.
225 pub struct Subscriber< struct
234 /// A `Subscriber` that logs formatted representations of `tracing` events. argument
243 /// Configures and constructs `Subscriber`s.
257 /// Returns a new [`SubscriberBuilder`] for configuring a [formatting subscriber].
263 /// Using [`init`] to set the default subscriber:
278 /// // Set the subscriber as the default.
282 /// [`try_init`] returns an error if the default subscriber could not be set:
289 /// // Configure the subscriber to emit logs in JSON format.
291 /// // Configure the subscriber to flatten event fields in the output JSON objects.
293 /// // Set the subscriber as the default, returning an error if this fails.
300 /// Rather than setting the subscriber as the default, [`finish`] _returns_ the
301 /// constructed subscriber, which may then be passed to other functions:
304 /// let subscriber = tracing_subscriber::fmt()
309 /// tracing::subscriber::with_default(subscriber, || {
310 /// // the subscriber will only be set as the default
315 /// [formatting subscriber]: Subscriber
326 /// construct a [`Subscriber`].
338 impl Subscriber { impl
339 /// The maximum [verbosity level] that is enabled by a `Subscriber` by
348 /// Returns a new `SubscriberBuilder` for configuring a format subscriber.
353 /// Returns a new format subscriber with the default configuration.
359 impl Default for Subscriber { implementation
365 // === impl Subscriber ===
367 impl<N, E, F, W> tracing_core::Subscriber for Subscriber<N, E, F, W> implementation
373 layer::Layered<F, Formatter<N, E, W>>: tracing_core::Subscriber,
451 impl<'a, N, E, F, W> LookupSpan<'a> for Subscriber<N, E, F, W> implementation
467 filter: Subscriber::DEFAULT_MAX_LEVEL, in default()
483 pub fn finish(self) -> Subscriber<N, E, F, W> { in finish()
484 let subscriber = self.inner.with_subscriber(Registry::default()); in finish() localVariable
485 Subscriber { in finish()
486 inner: self.filter.with_subscriber(subscriber), in finish()
490 /// Install this Subscriber as the global default if one is
498 /// because a global subscriber was already installed by another
507 /// Install this Subscriber as the global default.
514 /// global subscriber was already installed by another call to `try_init`.
517 .expect("Unable to install global subscriber") in init()
597 /// let subscriber = fmt()
603 /// this formatter; they will not be recorded by other `Subscriber`s or by
604 /// `Layer`s added to this subscriber.
738 /// Sets the subscriber being built to use a less verbose formatter.
751 …/// Sets the subscriber being built to use an [excessively pretty, human-readable formatter](crate…
763 /// Sets the subscriber being built to use a JSON formatter.
784 /// Sets the json subscriber being built to flatten event metadata.
797 /// Sets whether or not the JSON subscriber being built will include the current span
811 /// Sets whether or not the JSON subscriber being built will include a list (from
830 Formatter<N, E, W>: tracing_core::Subscriber + 'static,
832 /// Configures the subscriber being built to allow filter reloading at
850 Formatter<N, E, W>: tracing_core::Subscriber + 'static,
852 /// Returns a `Handle` that may be used to reload the constructed subscriber's
860 /// Sets the field formatter that the subscriber being built will use to record
875 /// let subscriber = tracing_subscriber::fmt()
878 /// # drop(subscriber)
890 /// Sets the [`EnvFilter`] that the subscriber will use to determine if
945 Formatter<N, E, W>: tracing_core::Subscriber + 'static, in with_env_filter()
955 /// subscriber.
972 /// This subscriber won't record any spans or events!
976 /// let subscriber = fmt()
994 /// Sets the [event formatter][`FormatEvent`] that the subscriber being built
1008 /// let subscriber = tracing_subscriber::fmt()
1026 /// Sets the [`MakeWriter`] that the subscriber being built will use to write events.
1050 /// Configures the subscriber to support [`libtest`'s output capturing][capturing] when used in
1062 /// use tracing::subscriber;
1064 /// subscriber::set_default(
1083 /// This sets the event formatter that the subscriber being built will use to record fields.
1090 /// let subscriber = tracing_subscriber::fmt()
1108 /// This sets the field formatter that the subscriber being built will use to record fields.
1116 /// let subscriber = tracing_subscriber::fmt()
1132 /// This sets the [`MakeWriter`] that the subscriber being built will use to write events.
1158 /// Install a global tracing subscriber that listens for events and
1177 /// likely because a global subscriber was already installed by another
1184 let builder = Subscriber::builder(); in try_init()
1190 // subscriber; it will be added to the `Targets` filter instead if no filter in try_init()
1197 let subscriber = builder.finish(); in try_init() localVariable
1199 let subscriber = { in try_init() localVariable
1209 Targets::new().with_default(Subscriber::DEFAULT_MAX_LEVEL) in try_init()
1213 Targets::new().with_default(Subscriber::DEFAULT_MAX_LEVEL) in try_init()
1216 subscriber.with(targets) in try_init()
1219 subscriber.try_init().map_err(Into::into) in try_init()
1222 /// Install a global tracing subscriber that listens for events and
1225 /// The configuration of the subscriber initialized by this function
1242 /// global subscriber was already installed by another call to `try_init`.
1246 try_init().expect("Unable to install global subscriber") in init()
1257 Subscriber,
1336 let subscriber = Subscriber::builder().event_format(f).finish(); in impls() localVariable
1337 let _dispatch = Dispatch::new(subscriber); in impls()
1340 let subscriber = Subscriber::builder().event_format(f).finish(); in impls() localVariable
1341 let _dispatch = Dispatch::new(subscriber); in impls()
1344 let subscriber = Subscriber::builder().event_format(f).finish(); in impls() localVariable
1345 let _dispatch = Dispatch::new(subscriber); in impls()
1350 let subscriber = Subscriber::builder().finish(); in subscriber_downcasts() localVariable
1351 let dispatch = Dispatch::new(subscriber); in subscriber_downcasts()
1352 assert!(dispatch.downcast_ref::<Subscriber>().is_some()); in subscriber_downcasts()
1357 let subscriber = Subscriber::new(); in subscriber_downcasts_to_parts() localVariable
1358 let dispatch = Dispatch::new(subscriber); in subscriber_downcasts_to_parts()
1367 let subscriber = Subscriber::new(); in is_lookup_span() localVariable
1368 assert_lookup_span(subscriber) in is_lookup_span()