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

Ath*_*har 4 logging rust

我正在构建一个 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");
Run Code Online (Sandbox Code Playgroud)

上面的代码出错了:

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
Run Code Online (Sandbox Code Playgroud)

我试过了:

  • try_current_local_offset与时间箱一起使用
  • 使用计时

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

Ath*_*har 5

本杰明·布鲁茨的评论建议奏效了。所以这是解决方案:

SimpleLogger::new().with_utc_timestamps().init().unwrap();
Run Code Online (Sandbox Code Playgroud)

这将创建一个带有 UTC 时间戳的记录器实例。所有功劳都归于上述用户:)