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

Could not determine the UTC offset on this system #51

Closed stevemk14ebr closed 2 years ago

stevemk14ebr commented 2 years ago
thread 'main' panicked at 'Could not determine the UTC offset on this system. Possible causes are that the time crate does not implement "local_offset_at" on your system, or that you are running in a multi-threaded environment and the time crate is returning "None" from "local_offset_at" to avoid unsafe behaviour. See the time crate's documentation for more information. (https://time-rs.github.io/internal-api/time/index.html#feature-flags): IndeterminateOffset', /home/steve/.cargo/registry/src/github.com-1ecc6299db9ec823/simple_logger-1.16.0/src/lib.rs:409:85
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Using initialization code:

 simple_logger::SimpleLogger::new()
    .with_level(LevelFilter::Warn)
    .with_module_level("filter", verbosity)
    .init().unwrap();

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.

borntyping commented 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.

borntyping commented 2 years ago

Are you running a program that uses multiple threads, or is this happening in a single threaded application?

stevemk14ebr commented 2 years ago

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 ...
}
borntyping commented 2 years ago

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.

  1. Use UTC time: SimpleLogger::new().with_utc_timestamps().init().unwrap();
  2. Disable timestamps: SimpleLogger::new().without_timestamps().init().unwrap();
  3. Use the time crate's unsafe features: RUSTFLAGS="--cfg unsound_local_offset" (docs)
borntyping commented 2 years ago

UTC timestamps are now the default in simple_logger 2.0.0.