初始化时的简单记录器错误

Simple Logger erroring on init

我正在构建一个 Rust 应用程序,我正在使用 Simple Logger 来记录我的应用程序的初始化。我的 main.rs 看起来像这样:

use log::info;
use simple_logger::SimpleLogger;

fn main() {
    SimpleLogger::new().init().unwrap();


    let (event_loop, mut interface) = create_interface();
    info!("Game interface created");

以上代码错误:

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/athul/.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

我试过:

但错误仍然存​​在。很可能我没有为我的应用程序正确初始化我的时间。最好(也是最简单)的方法是什么?

Benjamin Brootz 的评论建议奏效了。所以这是解决方案:

SimpleLogger::new().with_utc_timestamps().init().unwrap();

这将创建一个带有 UTC 时间戳的记录器实例。上述用户的所有学分:)