【问题标题】:Simple Logger erroring on init初始化时的简单记录器错误
【发布时间】:2022-01-25 22:40:44
【问题描述】:

我正在构建一个 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

我试过了:

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

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

【问题讨论】:

标签: logging rust


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2012-07-25
    • 2013-09-04
    • 1970-01-01
    • 2014-11-08
    • 1970-01-01
    • 2021-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多