pub trait SubscriberInitExtwhere
    Self: Into<Dispatch>,{
    // Provided methods
    fn set_default(self) -> DefaultGuard { ... }
    fn try_init(self) -> Result<(), TryInitError> { ... }
    fn init(self) { ... }
}
Expand description

Extension trait adding utility methods for subscriber initialization.

This trait provides extension methods to make configuring and setting a default subscriber more ergonomic. It is automatically implemented for all types that can be converted into a trace dispatcher. Since Dispatch implements From<T> for all T: Subscriber, all Subscriber implementations will implement this extension trait as well. Types which can be converted into Subscribers, such as builders that construct a Subscriber, may implement Into<Dispatch>, and will also receive an implementation of this trait.

Provided Methods§

source

fn set_default(self) -> DefaultGuard

Sets self as the default subscriber in the current scope, returning a guard that will unset it when dropped.

If the “tracing-log” feature flag is enabled, this will also initialize a log compatibility layer. This allows the subscriber to consume log::Records as though they were tracing Events.

source

fn try_init(self) -> Result<(), TryInitError>

Attempts to set self as the global default subscriber in the current scope, returning an error if one is already set.

If the “tracing-log” feature flag is enabled, this will also attempt to initialize a log compatibility layer. This allows the subscriber to consume log::Records as though they were tracing Events.

This method returns an error if a global default subscriber has already been set, or if a log logger has already been set (when the “tracing-log” feature is enabled).

source

fn init(self)

Attempts to set self as the global default subscriber in the current scope, panicking if this fails.

If the “tracing-log” feature flag is enabled, this will also attempt to initialize a log compatibility layer. This allows the subscriber to consume log::Records as though they were tracing Events.

This method panics if a global default subscriber has already been set, or if a log logger has already been set (when the “tracing-log” feature is enabled).

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T> SubscriberInitExt for Twhere T: Into<Dispatch>,