Trait FormatTime

Source
pub trait FormatTime {
    // Required methods
    fn format_time(&self, w: &mut impl Write) -> Result;
    fn style_timestamp(
        &self,
        ansi: bool,
        elapsed: Duration,
        w: &mut impl Write,
    ) -> Result;
}
Expand description

A type that can measure and format the current time.

This trait is used by HierarchicalLayer to include a timestamp with each Event when it is logged.

Notable default implementations of this trait are [LocalDateTime] and (). The former prints the current time as reported by time’s OffsetDateTime (note that it requires a time feature to be enabled and may panic! make sure to check out the docs for the [LocalDateTime]), and the latter does not print the current time at all.

Inspired by the FormatTime trait from tracing-subscriber.

Required Methods§

Source

fn format_time(&self, w: &mut impl Write) -> Result

Source

fn style_timestamp( &self, ansi: bool, elapsed: Duration, w: &mut impl Write, ) -> Result

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl FormatTime for ()

Default do-nothing time formatter.

Source§

fn format_time(&self, _w: &mut impl Write) -> Result

Source§

fn style_timestamp( &self, _ansi: bool, _elapsed: Duration, _w: &mut impl Write, ) -> Result

Source§

impl<'a, F> FormatTime for &'a F
where F: FormatTime,

Source§

fn format_time(&self, w: &mut impl Write) -> Result

Source§

fn style_timestamp( &self, ansi: bool, duration: Duration, w: &mut impl Write, ) -> Result

Implementors§