Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

A builder for the JSON formatter. This is used to configure the JSON formatter. The default configuration is:

  • level_name: “level”
  • level_value_casing: Casing::Lowercase
  • message_name: “message”
  • target_name: “target”
  • timestamp_name: “timestamp”
  • timestamp_format: TimestampFormat::Rfc3339
  • line_numbers: false
  • file_names: false
  • flatten_fields: true
  • flatten_spans: true

§Examples

use tracing_subscriber::prelude::*;

tracing_subscriber::registry()
    .with(
        tracing_ndjson::Builder::default()
            .with_level_name("severity")
            .with_level_value_casing(tracing_ndjson::Casing::Uppercase)
            .with_message_name("msg")
            .with_timestamp_name("ts")
            .with_timestamp_format(tracing_ndjson::TimestampFormat::Unix)
            .layer(),
    ).init();

tracing::info!(life = 42, "Hello, world!");

Implementations§

Source§

impl Builder

Source

pub fn new() -> Self

Source§

impl Builder

Source

pub fn with_level_name(self, level_name: &'static str) -> Self

Set the field name for the level field. The default is “level”.

Source

pub fn with_level_value_casing(self, casing: Casing) -> Self

Set the casing for the level field value. The default is Casing::Lowercase.

Source

pub fn with_message_name(self, message_name: &'static str) -> Self

Set the field name for the message field. The default is “message”.

Source

pub fn with_target_name(self, target_name: &'static str) -> Self

Set the field name for the target field. The default is “target”.

Source

pub fn with_timestamp_name(self, timestamp_name: &'static str) -> Self

Set the field name for the timestamp field. The default is “timestamp”.

Source

pub fn with_timestamp_format(self, timestamp_format: TimestampFormat) -> Self

Set the timestamp format for the timestamp field. The default is TimestampFormat::Rfc3339.

Source

pub fn with_flatten_fields(self, flatten_fields: bool) -> Self

Set whether to flatten fields. The default is true. If false, fields will be nested under a “fields” object.

Source

pub fn with_flatten_spans(self, flatten_spans: bool) -> Self

Set whether to flatten spans.

Source

pub fn with_line_numbers(self, line_numbers: bool) -> Self

Set whether to include line numbers.

Source

pub fn with_file_names(self, file_names: bool) -> Self

Set whether to include file names.

Source

pub fn with_field_filter( self, filter: impl Fn(&str) -> bool + Send + Sync + 'static, ) -> Self

Set a predicate that controls which fields appear in the JSON output. Fields for which the predicate returns false are omitted from output but are still recorded in span storage and visible to other layers.

Source

pub fn layer<S>(self) -> impl Layer<S>
where S: Subscriber + for<'a> LookupSpan<'a>,

Trait Implementations§

Source§

impl Default for Builder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.