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

Error message using feature timestamp #44

Closed uggla closed 2 years ago

uggla commented 2 years ago

Hello Sam,

I have the following message compiling my program. I try to activate the threads feature, but I still get the error message below. Of course, if I disable the timestamp feature, it works. Could you advise how to fix this issue as it appears unclear to me ?

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/uggla/rust/registry/src/github.com-1ecc6299db9ec823/simple_logger-1.15.1/src/lib.rs:360:64
uggla commented 2 years ago

Ok I think I get it:

/// Obtain the system's UTC offset.
#[cfg(any(target_os = "linux", target_os = "freebsd", unsound_local_offset))]
pub(super) fn local_offset_at(datetime: OffsetDateTime) -> Option<UtcOffset> {
    // Ensure that the process is single-threaded unless the user has explicitly opted out of this
    // check. This is to prevent issues with the environment being mutated by a different thread in
    // the process while execution of this function is taking place, which can cause a segmentation
    // fault by dereferencing a dangling pointer.
    if !cfg!(unsound_local_offset) && num_threads::is_single_threaded() != Some(true) {
        return None;
    }

    // Safety: We have just confirmed that the process is single-threaded or the user has explicitly
    // opted out of soundness.
    let tm = unsafe { timestamp_to_tm(datetime.unix_timestamp()) }?;
    tm_to_offset(tm)
}

https://time-rs.github.io/internal-api/time/sys/local_offset_at/imp/fn.timestamp_to_tm.html

borntyping commented 2 years ago

There's some more information on this issue: https://github.com/borntyping/rust-simple_logger/issues/43

borntyping commented 2 years ago

Released v1.16.0 with options to use UTC timestamps. Thanks!

borntyping commented 2 years ago

UTC timestamps are now the default in simple_logger 2.0.0.