logo
pub struct Format<F = Full, T = SystemTime> { /* private fields */ }
Available on crate features fmt and std only.
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 is intended to produce shorter log lines; it displays each event’s fields, along with fields from the current span context, but other information is abbreviated. The Pretty logging format is an extra-verbose, multi-line human-readable logging format intended for use in development.

Implementations

Use a less verbose output format.

See Compact.

Available on crate feature ansi only.

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();
Available on crate feature json only.

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 "time" feature flag enables the additional time formatters UtcTime and LocalTime, which use the time crate to provide more sophisticated timestamp formatting options.

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.

Sets whether or not an event’s source code file path is displayed.

Sets whether or not an event’s source code line number is displayed.

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

This is equivalent to calling Format::with_file and Format::with_line_number with the same value.

Available on crate feature json only.

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.

Available on crate feature json only.

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

See format::Json

Available on crate feature json only.

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 Writer.
Write a log message for Event in Context to the given Writer.
Write a log message for Event in Context to the given Writer.
Write a log message for Event in Context to the given Writer.

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
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.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more