Skip to main content

Pretty

Struct Pretty 

Source
pub struct Pretty;
Available on crate feature forest only.
Expand description

Format logs for pretty printing.

§Interpreting span times

Spans have the following format:

<NAME> [ <DURATION> | <BODY> / <ROOT> ]
  • DURATION represents elapsed time while the span has at least one active entry. Overlapping entries into the same span count once. If the span instruments a Future, time between polls does not count because the span is not entered then.
  • BODY represents the percent time the span is entered relative to the root span, excluding time that any child spans are entered.
  • ROOT represents the percent time the span is entered relative to the root span, including time that any child spans are entered.

As a mental model, look at ROOT to quickly narrow down which branches are costly, and look at BODY to pinpoint exactly which spans are expensive.

Spans without any child spans would have the same BODY and ROOT, so the redundancy is omitted. Durations accumulate child work: overlapping children contribute separately, and a parent’s total is raised to at least their sum. Totals can therefore exceed wall-clock time; see Span::total_duration. A root with zero duration displays 0.00% for all percentages.

With forest-cpu-time, an additional [ user: <TIME> | sys: <TIME> ] shows inclusive user and kernel CPU time. This is omitted on unsupported platforms or when measurements are incomplete. CPU times exclude blocked time and include parallel children; elapsed-time percentages are unchanged.

Use Pretty::with_max_level to omit less important nodes from the output while retaining their more important descendants and the original durations.

§Examples

An arbitrarily complex example:

INFO     try_from_entry_ro [ 324µs | 8.47% / 100.00% ]
INFO     ┝━ server::internal_search [ 296µs | 19.02% / 91.53% ]
INFO     │  ┝━ i [filter.info]: Some filter info...
INFO     │  ┝━ server::search [ 226µs | 10.11% / 70.01% ]
INFO     │  │  ┝━ be::search [ 181µs | 6.94% / 55.85% ]
INFO     │  │  │  ┕━ be::search -> filter2idl [ 158µs | 19.65% / 48.91% ]
INFO     │  │  │     ┝━ be::idl_arc_sqlite::get_idl [ 20.4µs | 6.30% ]
INFO     │  │  │     │  ┕━ i [filter.info]: Some filter info...
INFO     │  │  │     ┕━ be::idl_arc_sqlite::get_idl [ 74.3µs | 22.96% ]
ERROR    │  │  │        ┝━ 🚨 [admin.error]: On no, an admin error occurred :(
DEBUG    │  │  │        ┝━ 🐛 [debug]: An untagged debug log
INFO     │  │  │        ┕━ i [admin.info]: there's been a big mistake | alive: false | status: "very sad"
INFO     │  │  ┕━ be::idl_arc_sqlite::get_identry [ 13.1µs | 4.04% ]
ERROR    │  │     ┝━ 🔐 [security.critical]: A security critical log
INFO     │  │     ┕━ 🔓 [security.access]: A security access log
INFO     │  ┕━ server::search<filter_resolve> [ 8.08µs | 2.50% ]
WARN     │     ┕━ 🚧 [filter.warn]: Some filter warning
TRACE    ┕━ 📍 [trace]: Finished!

Implementations§

Source§

impl Pretty

Source

pub const fn with_max_level(self, max_level: LevelFilter) -> FilteredPretty

Select the most verbose level to include in formatted output.

For example, LevelFilter::WARN retains warnings and errors. Visible descendants of omitted spans are promoted without changing their order or the durations used for percentages. LevelFilter::OFF produces an empty string, and LevelFilter::TRACE produces the same output as Pretty. This filters formatting only; the collected tree is unchanged.

use gix_trace::forest::{Printer, printer::Pretty};
use tracing::metadata::LevelFilter;

let printer = Printer::new().formatter(Pretty.with_max_level(LevelFilter::WARN));

Trait Implementations§

Source§

impl Debug for Pretty

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Formatter for Pretty

Source§

type Error = Error

The error type if the Tree cannot be stringified.
Source§

fn fmt(&self, tree: &Tree) -> Result<String, Error>

Stringifies the Tree, or returns an error. Read more

Auto Trait Implementations§

§

impl Forget for Pretty

§

impl Freeze for Pretty

§

impl Move for Pretty

§

impl RefUnwindSafe for Pretty

§

impl Send for Pretty

§

impl Sync for Pretty

§

impl Unpin for Pretty

§

impl UnsafeUnpin for Pretty

§

impl UnwindSafe for Pretty

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

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

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more