logo
pub struct Format<F = Full, T = SystemTime> { /* private fields */ }
Expand description

A pre-configured event formatter.

You will usually want to use this as the FormatEvent for a FmtSubscriber.

The default logging format, Full includes all fields in each event and its containing spans. The Compact logging format includes only the fields from the most-recently-entered span.

Implementations

Sets whether or not the source code location from which an event originated is displayed.

This defaults to true.

Use a less verbose output format.

See Compact.

Use an excessively pretty, human-readable output format.

See Pretty.

Note that this requires the “ansi” feature to be enabled.

Options

Format::with_ansi can be used to disable ANSI terminal escape codes (which enable formatting such as colors, bold, italic, etc) in event formatting. However, a field formatter must be manually provided to avoid ANSI in the formatting of parent spans, like so:

tracing_subscriber::fmt()
   .pretty()
   .with_ansi(false)
   .fmt_fields(format::PrettyFields::new().with_ansi(false))
   // ... other settings ...
   .init();

Use the full JSON format.

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

Use the given timer for log message timestamps.

See time module for the provided timer implementations.

Note that using the chrono feature flag enables the additional time formatters ChronoUtc and ChronoLocal.

Do not emit timestamps with log messages.

Enable ANSI terminal colors for formatted output.

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

Sets whether or not an event’s level is displayed.

Sets whether or not the thread ID of the current thread is displayed when formatting events

Sets whether or not the name of the current thread is displayed when formatting events

Use the full JSON format with the event’s event fields flattened.

Example Output
{"timestamp":"Feb 20 11:28:15.096","level":"INFO","target":"mycrate", "message":"some message", "key": "value"}

See Json.

Sets whether or not the formatter will include the current span in formatted events.

See format::Json

Sets whether or not the formatter will include a list (from root to leaf) of all currently entered spans in formatted events.

See format::Json

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Write a log message for Event in Context to the given Write.

Write a log message for Event in Context to the given Write.

Write a log message for Event in Context to the given Write.

Write a log message for Event in Context to the given Write.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.