[−][src]Struct tracing_subscriber::fmt::SubscriberBuilder
feature="fmt"
only.Configures and constructs Subscriber
s.
Methods
impl<N, E, F, W> SubscriberBuilder<N, E, F, W> where
N: for<'writer> FormatFields<'writer> + 'static,
E: FormatEvent<Registry, N> + 'static,
W: MakeWriter + 'static,
F: Layer<Formatter<N, E, W>> + Send + Sync + 'static,
Layer<Registry, N, E, W>: Layer<Registry> + Send + Sync + 'static,
[src]
N: for<'writer> FormatFields<'writer> + 'static,
E: FormatEvent<Registry, N> + 'static,
W: MakeWriter + 'static,
F: Layer<Formatter<N, E, W>> + Send + Sync + 'static,
Layer<Registry, N, E, W>: Layer<Registry> + Send + Sync + 'static,
pub fn finish(self) -> Subscriber<N, E, F, W>
[src]
feature="fmt"
only.Finish the builder, returning a new FmtSubscriber
.
pub fn try_init(self) -> Result<(), Box<dyn Error + Send + Sync + 'static>>
[src]
feature="fmt"
only.Install this Subscriber as the global default if one is not already set.
If the tracing-log
feature is enabled, this will also install
the LogTracer to convert Log
records into tracing
Event
s.
Errors
Returns an Error if the initialization was unsuccessful, likely
because a global subscriber was already installed by another
call to try_init
.
pub fn init(self)
[src]
feature="fmt"
only.Install this Subscriber as the global default.
If the tracing-log
feature is enabled, this will also install
the LogTracer to convert Log
records into tracing
Event
s.
Panics
Panics if the initialization was unsuccessful, likely because a
global subscriber was already installed by another call to try_init
.
impl<N, L, T, F, W> SubscriberBuilder<N, Format<L, T>, F, W> where
N: for<'writer> FormatFields<'writer> + 'static,
[src]
N: for<'writer> FormatFields<'writer> + 'static,
pub fn with_timer<T2>(
self,
timer: T2
) -> SubscriberBuilder<N, Format<L, T2>, F, W>
[src]
self,
timer: T2
) -> SubscriberBuilder<N, Format<L, T2>, F, W>
feature="fmt"
only.Use the given timer
for log message timestamps.
See time
for the provided timer implementations.
Note that using the chrono
feature flag enables the
additional time formatters ChronoUtc
and ChronoLocal
.
pub fn without_time(self) -> SubscriberBuilder<N, Format<L, ()>, F, W>
[src]
feature="fmt"
only.Do not emit timestamps with log messages.
pub fn with_ansi(self, ansi: bool) -> SubscriberBuilder<N, Format<L, T>, F, W>
[src]
feature="fmt"
and feature="ansi"
only.Enable ANSI encoding for formatted events.
pub fn with_target(
self,
display_target: bool
) -> SubscriberBuilder<N, Format<L, T>, F, W>
[src]
self,
display_target: bool
) -> SubscriberBuilder<N, Format<L, T>, F, W>
feature="fmt"
only.Sets whether or not an event's target is displayed.
pub fn with_level(
self,
display_level: bool
) -> SubscriberBuilder<N, Format<L, T>, F, W>
[src]
self,
display_level: bool
) -> SubscriberBuilder<N, Format<L, T>, F, W>
feature="fmt"
only.Sets whether or not an event's level is displayed.
pub fn compact(self) -> SubscriberBuilder<N, Format<Compact, T>, F, W> where
N: for<'writer> FormatFields<'writer> + 'static,
[src]
N: for<'writer> FormatFields<'writer> + 'static,
feature="fmt"
only.Sets the subscriber being built to use a less verbose formatter.
See format::Compact
.
pub fn json(self) -> SubscriberBuilder<JsonFields, Format<Json, T>, F, W> where
N: for<'writer> FormatFields<'writer> + 'static,
[src]
N: for<'writer> FormatFields<'writer> + 'static,
feature="fmt"
and feature="json"
only.Sets the subscriber being built to use a JSON formatter.
See format::Json
impl<T, F, W> SubscriberBuilder<JsonFields, Format<Json, T>, F, W>
[src]
pub fn flatten_event(
self,
flatten_event: bool
) -> SubscriberBuilder<JsonFields, Format<Json, T>, F, W>
[src]
self,
flatten_event: bool
) -> SubscriberBuilder<JsonFields, Format<Json, T>, F, W>
feature="fmt"
and feature="json"
only.Sets the json subscriber being built to flatten event metadata.
See format::Json
impl<N, E, W> SubscriberBuilder<N, E, EnvFilter, W> where
Formatter<N, E, W>: Subscriber + 'static,
[src]
Formatter<N, E, W>: Subscriber + 'static,
pub fn with_filter_reloading(
self
) -> SubscriberBuilder<N, E, Layer<EnvFilter, Formatter<N, E, W>>, W>
[src]
self
) -> SubscriberBuilder<N, E, Layer<EnvFilter, Formatter<N, E, W>>, W>
feature="fmt"
and feature="env-filter"
only.Configures the subscriber being built to allow filter reloading at runtime.
impl<N, E, W> SubscriberBuilder<N, E, Layer<EnvFilter, Formatter<N, E, W>>, W> where
Formatter<N, E, W>: Subscriber + 'static,
[src]
Formatter<N, E, W>: Subscriber + 'static,
pub fn reload_handle(&self) -> Handle<EnvFilter, Formatter<N, E, W>>
[src]
feature="fmt"
and feature="env-filter"
only.Returns a Handle
that may be used to reload the constructed subscriber's
filter.
impl<N, E, F, W> SubscriberBuilder<N, E, F, W>
[src]
pub fn fmt_fields<N2>(self, fmt_fields: N2) -> SubscriberBuilder<N2, E, F, W> where
N2: for<'writer> FormatFields<'writer> + 'static,
[src]
N2: for<'writer> FormatFields<'writer> + 'static,
feature="fmt"
only.Sets the Visitor that the subscriber being built will use to record fields.
For example:
use tracing_subscriber::fmt::{Subscriber, format}; use tracing_subscriber::prelude::*; let formatter = // Construct a custom formatter for `Debug` fields format::debug_fn(|writer, field, value| write!(writer, "{}: {:?}", field, value)) // Use the `tracing_subscriber::MakeFmtExt` trait to wrap the // formatter so that a delimiter is added between fields. .delimited(", "); let subscriber = Subscriber::builder() .fmt_fields(formatter) .finish();
pub fn with_env_filter(
self,
filter: impl Into<EnvFilter>
) -> SubscriberBuilder<N, E, EnvFilter, W> where
Formatter<N, E, W>: Subscriber + 'static,
[src]
self,
filter: impl Into<EnvFilter>
) -> SubscriberBuilder<N, E, EnvFilter, W> where
Formatter<N, E, W>: Subscriber + 'static,
feature="fmt"
and feature="env-filter"
only.Sets the EnvFilter
that the subscriber will use to determine if
a span or event is enabled.
Note that this method requires the "env-filter" feature flag to be enabled.
If a filter was previously set, or a maximum level was set by the
with_max_level
method, that value is replaced by the new filter.
Examples
Setting a filter based on the value of the RUST_LOG
environment
variable:
use tracing_subscriber::{FmtSubscriber, EnvFilter}; let subscriber = FmtSubscriber::builder() .with_env_filter(EnvFilter::from_default_env()) .finish();
Setting a filter based on a pre-set filter directive string:
use tracing_subscriber::FmtSubscriber; let subscriber = FmtSubscriber::builder() .with_env_filter("my_crate=info,my_crate::my_mod=debug,[my_span]=trace") .finish();
Adding additional directives to a filter constructed from an env var:
use tracing_subscriber::{ FmtSubscriber, filter::{EnvFilter, LevelFilter}, }; let filter = EnvFilter::try_from_env("MY_CUSTOM_FILTER_ENV_VAR")? // Set the base level when not matched by other directives to WARN. .add_directive(LevelFilter::WARN.into()) // Set the max level for `my_crate::my_mod` to DEBUG, overriding // any directives parsed from the env variable. .add_directive("my_crate::my_mod=debug".parse()?); let subscriber = FmtSubscriber::builder() .with_env_filter(filter) .finish();
pub fn with_max_level(
self,
filter: impl Into<LevelFilter>
) -> SubscriberBuilder<N, E, LevelFilter, W>
[src]
self,
filter: impl Into<LevelFilter>
) -> SubscriberBuilder<N, E, LevelFilter, W>
feature="fmt"
only.Sets the maximum verbosity level that will be enabled by the subscriber.
If the max level has already been set, or a EnvFilter
was added by
with_filter
, this replaces that configuration with the new
maximum level.
Examples
Enable up to the DEBUG
verbosity level:
use tracing_subscriber::FmtSubscriber; use tracing::Level; let subscriber = FmtSubscriber::builder() .with_max_level(Level::DEBUG) .finish();
This subscriber won't record any spans or events!
use tracing_subscriber::{ FmtSubscriber, filter::LevelFilter, }; let subscriber = FmtSubscriber::builder() .with_max_level(LevelFilter::OFF) .finish();
pub fn event_format<E2>(self, fmt_event: E2) -> SubscriberBuilder<N, E2, F, W> where
E2: FormatEvent<Registry, N> + 'static,
N: for<'writer> FormatFields<'writer> + 'static,
W: MakeWriter + 'static,
[src]
E2: FormatEvent<Registry, N> + 'static,
N: for<'writer> FormatFields<'writer> + 'static,
W: MakeWriter + 'static,
feature="fmt"
only.Sets the function that the subscriber being built should use to format events that occur.
pub fn inherit_fields(self, inherit_fields: bool) -> Self
[src]
this no longer does anything
feature="fmt"
only.Sets whether or not spans inherit their parents' field values (disabled by default).
pub fn on_event<E2>(self, fmt_event: E2) -> SubscriberBuilder<N, E2, F, W> where
E2: FormatEvent<Registry, N> + 'static,
N: for<'writer> FormatFields<'writer> + 'static,
W: MakeWriter + 'static,
[src]
E2: FormatEvent<Registry, N> + 'static,
N: for<'writer> FormatFields<'writer> + 'static,
W: MakeWriter + 'static,
renamed to event_format
.
feature="fmt"
only.Sets the function that the subscriber being built should use to format events that occur.
pub fn with_writer<W2>(self, make_writer: W2) -> SubscriberBuilder<N, E, F, W2> where
W2: MakeWriter + 'static,
[src]
W2: MakeWriter + 'static,
feature="fmt"
only.Sets the MakeWriter
that the subscriber being built will use to write events.
Examples
Using stderr
rather than stdout
:
use std::io; let subscriber = tracing_subscriber::fmt::Subscriber::builder() .with_writer(io::stderr) .finish();
Trait Implementations
impl<N: Debug, E: Debug, F: Debug, W: Debug> Debug for SubscriberBuilder<N, E, F, W>
[src]
impl Default for SubscriberBuilder
[src]
Auto Trait Implementations
impl<N = DefaultFields, E = Format<Full, SystemTime>, F = LevelFilter, W = fn() -> Stdout> !RefUnwindSafe for SubscriberBuilder<N, E, F, W>
impl<N, E, F, W> Send for SubscriberBuilder<N, E, F, W> where
E: Send,
F: Send,
N: Send,
W: Send,
E: Send,
F: Send,
N: Send,
W: Send,
impl<N, E, F, W> Sync for SubscriberBuilder<N, E, F, W> where
E: Sync,
F: Sync,
N: Sync,
W: Sync,
E: Sync,
F: Sync,
N: Sync,
W: Sync,
impl<N, E, F, W> Unpin for SubscriberBuilder<N, E, F, W> where
E: Unpin,
F: Unpin,
N: Unpin,
W: Unpin,
E: Unpin,
F: Unpin,
N: Unpin,
W: Unpin,
impl<N = DefaultFields, E = Format<Full, SystemTime>, F = LevelFilter, W = fn() -> Stdout> !UnwindSafe for SubscriberBuilder<N, E, F, W>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,