[−][src]Struct tracing_subscriber::fmt::Layer
feature="fmt"
only.A Layer
that logs formatted representations of tracing
events.
Examples
Constructing a layer with the default configuration:
use tracing_subscriber::{fmt, Registry}; use tracing_subscriber::prelude::*; let subscriber = Registry::default() .with(fmt::Layer::default()); tracing::subscriber::set_global_default(subscriber).unwrap();
Overriding the layer's behavior:
use tracing_subscriber::{fmt, Registry}; use tracing_subscriber::prelude::*; let fmt_layer = fmt::layer() .with_target(false) // don't include event targets when logging .with_level(false); // don't include event levels when logging let subscriber = Registry::default().with(fmt_layer);
Setting a custom event formatter:
use tracing_subscriber::fmt::{self, format, time}; use tracing_subscriber::prelude::*; let fmt = format().with_timer(time::Uptime::default()); let fmt_layer = fmt::layer() .event_format(fmt) .with_target(false);
Methods
impl<S> Layer<S>
[src]
pub fn builder() -> LayerBuilder<S>
[src]
a separate layer builder is not necessary, use Layer::new
/Layer::default
instead
feature="fmt"
only.Returns a new LayerBuilder
for configuring a Layer
.
pub fn new() -> Self
[src]
feature="fmt"
only.Returns a new Layer
with the default configuration.
impl<S, N, E, W> Layer<S, N, E, W> where
S: Subscriber + for<'a> LookupSpan<'a>,
N: for<'writer> FormatFields<'writer> + 'static,
W: MakeWriter + 'static,
[src]
S: Subscriber + for<'a> LookupSpan<'a>,
N: for<'writer> FormatFields<'writer> + 'static,
W: MakeWriter + 'static,
pub fn event_format<E2>(self, e: E2) -> Layer<S, N, E2, W> where
E2: FormatEvent<S, N> + 'static,
[src]
E2: FormatEvent<S, N> + 'static,
feature="fmt"
only.Sets the event formatter 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
&mut dyn Write
, and an Event
.
Examples
Setting a type implementing FormatEvent
as the formatter:
use tracing_subscriber::fmt::{self, format}; let layer = fmt::layer() .event_format(format().compact());
impl<S, N, E, W> Layer<S, N, E, W>
[src]
pub fn with_writer<W2>(self, make_writer: W2) -> Layer<S, N, E, W2> where
W2: MakeWriter + 'static,
[src]
W2: MakeWriter + 'static,
feature="fmt"
only.Sets the MakeWriter
that the Layer
being built will use to write events.
Examples
Using stderr
rather than stdout
:
use std::io; use tracing_subscriber::fmt; let layer = fmt::layer() .with_writer(io::stderr);
impl<S, N, L, T, W> Layer<S, N, Format<L, T>, W> where
N: for<'writer> FormatFields<'writer> + 'static,
[src]
N: for<'writer> FormatFields<'writer> + 'static,
pub fn with_timer<T2>(self, timer: T2) -> Layer<S, N, Format<L, T2>, W>
[src]
feature="fmt"
only.Use the given timer
for span and event 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) -> Layer<S, N, Format<L, ()>, W>
[src]
feature="fmt"
only.Do not emit timestamps with spans and event.
pub fn with_ansi(self, ansi: bool) -> Layer<S, N, Format<L, T>, W>
[src]
feature="fmt"
and feature="ansi"
only.Enable ANSI encoding for formatted events.
pub fn with_target(self, display_target: bool) -> Layer<S, N, Format<L, T>, W>
[src]
feature="fmt"
only.Sets whether or not an event's target is displayed.
pub fn with_level(self, display_level: bool) -> Layer<S, N, Format<L, T>, W>
[src]
feature="fmt"
only.Sets whether or not an event's level is displayed.
pub fn compact(self) -> Layer<S, N, Format<Compact, T>, W> where
N: for<'writer> FormatFields<'writer> + 'static,
[src]
N: for<'writer> FormatFields<'writer> + 'static,
feature="fmt"
only.Sets the layer being built to use a less verbose formatter.
pub fn json(self) -> Layer<S, JsonFields, Format<Json, T>, W>
[src]
feature="fmt"
and feature="json"
only.Sets the layer being built to use a JSON formatter.
The full format includes fields from all entered spans.
Example Output
{"timestamp":"Feb 20 11:28:15.096","level":"INFO","target":"mycrate","fields":{"message":"some message", "key": "value"}}
Options
Layer::flatten_event
can be used to enable flattening event fields into the root object.
impl<S, T, W> Layer<S, JsonFields, Format<Json, T>, W>
[src]
pub fn flatten_event(
self,
flatten_event: bool
) -> Layer<S, JsonFields, Format<Json, T>, W>
[src]
self,
flatten_event: bool
) -> Layer<S, JsonFields, Format<Json, T>, W>
feature="fmt"
and feature="json"
only.Sets the JSON layer being built to flatten event metadata.
See format::Json
impl<S, N, E, W> Layer<S, N, E, W>
[src]
pub fn fmt_fields<N2>(self, fmt_fields: N2) -> Layer<S, N2, E, W> where
N2: for<'writer> FormatFields<'writer> + 'static,
[src]
N2: for<'writer> FormatFields<'writer> + 'static,
feature="fmt"
only.Sets the field formatter that the layer being built will use to record fields.
impl<S, N, E, W> Layer<S, N, E, W> where
S: Subscriber + for<'a> LookupSpan<'a>,
N: for<'writer> FormatFields<'writer> + 'static,
E: FormatEvent<S, N> + 'static,
W: MakeWriter + 'static,
[src]
S: Subscriber + for<'a> LookupSpan<'a>,
N: for<'writer> FormatFields<'writer> + 'static,
E: FormatEvent<S, N> + 'static,
W: MakeWriter + 'static,
pub fn finish(self) -> Layer<S, N, E, W>
[src]
LayerBuilder
is no longer a separate type; this method is not necessary
feature="fmt"
only.Builds a Layer
with the provided configuration.
Trait Implementations
impl<S: Debug, N: Debug, E: Debug, W: Debug> Debug for Layer<S, N, E, W>
[src]
impl<S> Default for Layer<S>
[src]
impl<S, N, E, W> Layer<S> for Layer<S, N, E, W> where
S: Subscriber + for<'a> LookupSpan<'a>,
N: for<'writer> FormatFields<'writer> + 'static,
E: FormatEvent<S, N> + 'static,
W: MakeWriter + 'static,
[src]
S: Subscriber + for<'a> LookupSpan<'a>,
N: for<'writer> FormatFields<'writer> + 'static,
E: FormatEvent<S, N> + 'static,
W: MakeWriter + 'static,
fn new_span(&self, attrs: &Attributes, id: &Id, ctx: Context<S>)
[src]
fn on_record(&self, id: &Id, values: &Record, ctx: Context<S>)
[src]
fn on_event(&self, event: &Event, ctx: Context<S>)
[src]
unsafe fn downcast_raw(&self, id: TypeId) -> Option<*const ()>
[src]
fn register_callsite(&self, metadata: &'static Metadata<'static>) -> Interest
[src]
fn enabled(&self, metadata: &Metadata, ctx: Context<S>) -> bool
[src]
fn on_follows_from(&self, _span: &Id, _follows: &Id, _ctx: Context<S>)
[src]
fn on_enter(&self, _id: &Id, _ctx: Context<S>)
[src]
fn on_exit(&self, _id: &Id, _ctx: Context<S>)
[src]
fn on_close(&self, _id: Id, _ctx: Context<S>)
[src]
fn on_id_change(&self, _old: &Id, _new: &Id, _ctx: Context<S>)
[src]
fn and_then<L>(self, layer: L) -> Layered<L, Self, S> where
L: Layer<S>,
Self: Sized,
[src]
L: Layer<S>,
Self: Sized,
fn with_subscriber(self, inner: S) -> Layered<Self, S> where
Self: Sized,
[src]
Self: Sized,
Auto Trait Implementations
impl<S, N, E, W> RefUnwindSafe for Layer<S, N, E, W> where
E: RefUnwindSafe,
N: RefUnwindSafe,
S: RefUnwindSafe,
W: RefUnwindSafe,
E: RefUnwindSafe,
N: RefUnwindSafe,
S: RefUnwindSafe,
W: RefUnwindSafe,
impl<S, N, E, W> Send for Layer<S, N, E, W> where
E: Send,
N: Send,
S: Send,
W: Send,
E: Send,
N: Send,
S: Send,
W: Send,
impl<S, N, E, W> Sync for Layer<S, N, E, W> where
E: Sync,
N: Sync,
S: Sync,
W: Sync,
E: Sync,
N: Sync,
S: Sync,
W: Sync,
impl<S, N, E, W> Unpin for Layer<S, N, E, W> where
E: Unpin,
N: Unpin,
S: Unpin,
W: Unpin,
E: Unpin,
N: Unpin,
S: Unpin,
W: Unpin,
impl<S, N, E, W> UnwindSafe for Layer<S, N, E, W> where
E: UnwindSafe,
N: UnwindSafe,
S: UnwindSafe,
W: UnwindSafe,
E: UnwindSafe,
N: UnwindSafe,
S: UnwindSafe,
W: UnwindSafe,
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>,