Closed stevemk14ebr closed 2 years ago
See https://github.com/borntyping/rust-simple_logger/issues/48, https://github.com/borntyping/rust-simple_logger/issues/47, https://github.com/borntyping/rust-simple_logger/issues/44, https://github.com/borntyping/rust-simple_logger/issues/43, https://github.com/borntyping/rust-simple_logger/issues/35.
I recommend using with_utc_timestamps()
:
simple_logger::SimpleLogger::new()
.with_level(LevelFilter::Warn)
.with_module_level("filter", verbosity)
.with_utc_timestamps()
.init().unwrap();
I'm currently working out if I can replace the current init()
methods with new ones to change the defaults - I'm unwilling to change the default from local time to UTC time in any way that might result in user's log formats silently changing from one timezone to another with no way to tell the difference.
Are you running a program that uses multiple threads, or is this happening in a single threaded application?
this is in a multi-threaded actix (tokio) application. My main looks like this:
#[actix_rt::main]
async fn main() {
simple_logger::SimpleLogger::new()
.with_level(LevelFilter::Warn)
.with_module_level("filter", verbosity)
.init().unwrap();
... stuff ...
}
This is unfortunately expected then. I'm working out what I can do to change the defaults in #52, as this is caused by a dependency.
There's a list of workarounds for simple_logger, depending on how you'd prefer to deal with the issue.
- Use UTC time:
SimpleLogger::new().with_utc_timestamps().init().unwrap();
- Disable timestamps:
SimpleLogger::new().without_timestamps().init().unwrap();
- Use the
time
crate's unsafe features:RUSTFLAGS="--cfg unsound_local_offset"
(docs)
UTC timestamps are now the default in simple_logger 2.0.0.
Using initialization code:
This occurs on a WSL2 console running debian. This is a really standard environment, perhaps the default could be to not try to localize the time instead, or fallback to another mode more gracefully.
I should also note this panic is 'new' after upgrading the library. The default mode now causes systems that previous ran to panic.