borntyping / rust-simple_logger

A rust logger that prints all messages with a readable output format.
https://crates.io/crates/simple_logger
MIT License
220 stars 48 forks source link

Including UTC offset when using `Timestamps::UtcOffset`? #61

Closed hismito closed 2 years ago

hismito commented 2 years ago

I create a logger like

simple_logger::SimpleLogger::new()
        .with_utc_offset(time::UtcOffset::current_local_offset().unwrap())
        .init()
        .unwrap();

at the very beginning of main() to not run into #44

This logger will format all offset-ed timestamps in UTC, which makes them looks like they are in UTC but actually not.

I found the relevant change at https://github.com/borntyping/rust-simple_logger/commit/496d76a5deaed9cd4ab67f73c601346ab6add8ee#diff-b1a35a68f14e696205874893c07fd24fdb88882b47c23cc0e0c80a30c7d53759R435

Maybe we can change it to use TIMESTAMP_FORMAT_OFFSET instead?

let instant = time::macros::datetime!(2020-03-04 05:06:07.800 +09:00);

println!("{}", instant.format(&TIMESTAMP_FORMAT_UTC).unwrap());     // 2020-03-04T05:06:07.800Z
println!("{}", instant.format(&TIMESTAMP_FORMAT_OFFSET).unwrap());  // 2020-03-04T05:06:07.800+09:00

In the example above, they both leaves 3 digits at fracitional part of second as requsted by #55

borntyping commented 2 years ago

Huh yeah, this is definitely a bug. Timestamps::UtcOffset should use TIMESTAMP_FORMAT_OFFSET not TIMESTAMP_FORMAT_UTC.

I'd welcome a PR to fix this, or will get round to it once I'm next on a machine I can easily do Rust dev on. :)