devlog_tracing/
time_format.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use core::fmt;

use chrono::Local;
use tracing_subscriber::fmt::{format::Writer, time::FormatTime};

#[derive(Default)]
pub struct DevLogTimeFormat {
    // Prevents direct struct initialization, so we can add fields here later as a non-breaking
    // change.
    _private: (),
}

impl FormatTime for DevLogTimeFormat {
    fn format_time(&self, writer: &mut Writer<'_>) -> fmt::Result {
        let time = Local::now();
        write!(writer, "[{}]", time.format("%H:%M:%S"))?;
        Ok(())
    }
}