#env-logger #timezone #logging #format #log-format #format-time

bin+lib env_logger_timezone_fmt

env_logger timezone format

2 releases

0.1.1 Apr 25, 2024
0.1.0 Apr 25, 2024

#9 in #env-logger

Download history 15/week @ 2024-07-25 42/week @ 2024-08-01 12/week @ 2024-08-08 9/week @ 2024-08-15 6/week @ 2024-08-22 11/week @ 2024-08-29 12/week @ 2024-09-05 27/week @ 2024-09-12 29/week @ 2024-09-19 23/week @ 2024-09-26 32/week @ 2024-10-03 36/week @ 2024-10-10 21/week @ 2024-10-17 21/week @ 2024-10-24 38/week @ 2024-10-31 37/week @ 2024-11-07

118 downloads per month
Used in rnacos

MIT/Apache

11KB
208 lines

logger timezone format

rust env_logger timezone format

example

use env_logger::{Env, TimestampPrecision};
use env_logger_timezone_fmt::{TimeZoneFormat, TimeZoneFormatEnv};
use std::sync::Arc;
use std::time::Duration;

fn main() {
    println!("hello, world!");
    // system local timezone
    //let timezone_fmt = Arc::new(TimeZoneFormatEnv::default());
    // system local timezone
    //let timezone_fmt = Arc::new(TimeZoneFormatEnv::new(None,Some(TimestampPrecision::Millis)));
    // GMT+8
    let timezone_fmt = Arc::new(TimeZoneFormatEnv::new(Some(8*60*60),Some(TimestampPrecision::Millis)));
    env_logger::Builder::from_env(Env::default().default_filter_or("info"))
        .format(move |buf, record| TimeZoneFormat::new(buf, &timezone_fmt).write(record))
        .init();
    log::info!("1");
    std::thread::sleep(Duration::from_millis(1000));
    log::info!("2");
    std::thread::sleep(Duration::from_millis(1000));
    log::info!("3");
}


GMT+8 output:

hello, world!
[2024-04-25 23:53:08.333 +08:00 INFO  env_logger_timezone_fmt] 1
[2024-04-25 23:53:09.337 +08:00 INFO  env_logger_timezone_fmt] 2
[2024-04-25 23:53:10.341 +08:00 INFO  env_logger_timezone_fmt] 3

Dependencies

~1.5MB
~24K SLoC