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

bin+lib env_logger_timezone_fmt

env_logger timezone format

2 releases

0.1.1 Apr 25, 2024
0.1.0 Apr 25, 2024

#7 in #env-logger

Download history 18/week @ 2024-06-24 32/week @ 2024-07-01 21/week @ 2024-07-08 13/week @ 2024-07-15 22/week @ 2024-07-29 45/week @ 2024-08-05 7/week @ 2024-08-12 10/week @ 2024-08-19 23/week @ 2024-09-02 38/week @ 2024-09-16 40/week @ 2024-09-23 2/week @ 2024-09-30 63/week @ 2024-10-07

143 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