[][src]Struct tracing_subscriber::fmt::LayerBuilder

pub struct LayerBuilder<S, N = DefaultFields, E = Format<Full>, W = fn() -> Stdout> { /* fields omitted */ }

A builder for Layer that logs formatted representations of tracing events and spans.

Examples

Constructing a layer with the default configuration:

use tracing_subscriber::fmt;
use tracing_subscriber::prelude::*;

let fmt_layer = fmt::Layer::builder().finish();

Overriding the layer's behavior:

use tracing_subscriber::fmt;
use tracing_subscriber::prelude::*;

let fmt_layer = fmt::Layer::builder()
   .with_target(false) // don't include event targets when logging
   .finish();

Setting a custom event formatter:

use tracing_subscriber::fmt::{self, format::Format, time};
use tracing_subscriber::prelude::*;

let fmt = Format::default().with_timer(time::Uptime::default());
let fmt_layer = fmt::Layer::builder()
    .event_format(fmt)
    .with_target(false)
    .finish();

Methods

impl<S, N, E, W> LayerBuilder<S, N, E, W> where
    S: Subscriber + for<'a> LookupSpan<'a>,
    N: for<'writer> FormatFields<'writer> + 'static,
    W: MakeWriter + 'static, 
[src]

pub fn event_format<E2>(self, e: E2) -> LayerBuilder<S, N, E2, W> where
    E2: FormatEvent<S, N> + 'static, 
[src]

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::builder()
    .event_format(format::Format::default().compact())
    .finish();

impl<S, N, E, W> LayerBuilder<S, N, E, W>[src]

pub fn with_writer<W2>(self, make_writer: W2) -> LayerBuilder<S, N, E, W2> where
    W2: MakeWriter + 'static, 
[src]

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::builder()
    .with_writer(io::stderr)
    .finish();

impl<S, N, L, T, W> LayerBuilder<S, N, Format<L, T>, W> where
    N: for<'writer> FormatFields<'writer> + 'static, 
[src]

pub fn with_timer<T2>(self, timer: T2) -> LayerBuilder<S, N, Format<L, T2>, W>[src]

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) -> LayerBuilder<S, N, Format<L, ()>, W>[src]

Do not emit timestamps with spans and event.

pub fn with_ansi(self, ansi: bool) -> LayerBuilder<S, N, Format<L, T>, W>[src]

Enable ANSI encoding for formatted events.

pub fn with_target(
    self,
    display_target: bool
) -> LayerBuilder<S, N, Format<L, T>, W>
[src]

Sets whether or not an event's target is displayed.

pub fn compact(self) -> LayerBuilder<S, N, Format<Compact, T>, W> where
    N: for<'writer> FormatFields<'writer> + 'static, 
[src]

Sets the layer being built to use a less verbose formatter.

pub fn json(self) -> LayerBuilder<S, JsonFields, Format<Json, T>, W>[src]

Sets the layer being built to use a JSON formatter.

impl<S, N, E, W> LayerBuilder<S, N, E, W>[src]

pub fn fmt_fields<N2>(self, fmt_fields: N2) -> LayerBuilder<S, N2, E, W> where
    N2: for<'writer> FormatFields<'writer> + 'static, 
[src]

Sets the field formatter that the layer being built will use to record fields.

impl<S, N, E, W> LayerBuilder<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]

pub fn finish(self) -> Layer<S, N, E, W>[src]

Builds a Layer with the provided configuration.

Trait Implementations

impl<S: Debug, N: Debug, E: Debug, W: Debug> Debug for LayerBuilder<S, N, E, W>[src]

impl<S> Default for LayerBuilder<S>[src]

Auto Trait Implementations

impl<S, N, E, W> RefUnwindSafe for LayerBuilder<S, N, E, W> where
    E: RefUnwindSafe,
    N: RefUnwindSafe,
    S: RefUnwindSafe,
    W: RefUnwindSafe

impl<S, N, E, W> Send for LayerBuilder<S, N, E, W> where
    E: Send,
    N: Send,
    S: Send,
    W: Send

impl<S, N, E, W> Sync for LayerBuilder<S, N, E, W> where
    E: Sync,
    N: Sync,
    S: Sync,
    W: Sync

impl<S, N, E, W> Unpin for LayerBuilder<S, N, E, W> where
    E: Unpin,
    N: Unpin,
    S: Unpin,
    W: Unpin

impl<S, N, E, W> UnwindSafe for LayerBuilder<S, N, E, W> where
    E: UnwindSafe,
    N: UnwindSafe,
    S: UnwindSafe,
    W: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.