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
impl Builder
Sourcepub fn with_level_name(self, level_name: &'static str) -> Self
pub fn with_level_name(self, level_name: &'static str) -> Self
Set the field name for the level field. The default is “level”.
Sourcepub fn with_level_value_casing(self, casing: Casing) -> Self
pub fn with_level_value_casing(self, casing: Casing) -> Self
Set the casing for the level field value. The default is Casing::Lowercase.
Sourcepub fn with_message_name(self, message_name: &'static str) -> Self
pub fn with_message_name(self, message_name: &'static str) -> Self
Set the field name for the message field. The default is “message”.
Sourcepub fn with_target_name(self, target_name: &'static str) -> Self
pub fn with_target_name(self, target_name: &'static str) -> Self
Set the field name for the target field. The default is “target”.
Sourcepub fn with_timestamp_name(self, timestamp_name: &'static str) -> Self
pub fn with_timestamp_name(self, timestamp_name: &'static str) -> Self
Set the field name for the timestamp field. The default is “timestamp”.
Sourcepub fn with_timestamp_format(self, timestamp_format: TimestampFormat) -> Self
pub fn with_timestamp_format(self, timestamp_format: TimestampFormat) -> Self
Set the timestamp format for the timestamp field. The default is TimestampFormat::Rfc3339.
Sourcepub fn with_flatten_fields(self, flatten_fields: bool) -> Self
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.
Sourcepub fn with_flatten_spans(self, flatten_spans: bool) -> Self
pub fn with_flatten_spans(self, flatten_spans: bool) -> Self
Set whether to flatten spans.
Sourcepub fn with_line_numbers(self, line_numbers: bool) -> Self
pub fn with_line_numbers(self, line_numbers: bool) -> Self
Set whether to include line numbers.
Sourcepub fn with_file_names(self, file_names: bool) -> Self
pub fn with_file_names(self, file_names: bool) -> Self
Set whether to include file names.
pub fn layer<S>(self) -> impl Layer<S>where
S: Subscriber + for<'a> LookupSpan<'a>,
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnwindSafe for Builder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more