gpt4 book ai didi

记录 Rust 程序

转载 作者:行者123 更新时间:2023-11-29 07:50:24 25 4
gpt4 key购买 nike

如果我们有如下代码

fn main() {
error!("This is an error log")
warn!("This is a warn log")
info!("this is an info log")
debug!("This is a debug log")
}

我们如何在 Windows 上启用调试级别输出?

最佳答案

当执行你的程序时,你需要适本地设置RUST_LOG环境变量;它是(就此而言)逗号分隔的键=值列表;键是 crate 或模块名称,例如extrastd::option;值是数字,映射到日志级别:

  • 1:错误
  • 2:警告
  • 3:信息
  • 4:调试

(每个级别包括更重要的级别。)

在命令提示符下,编译和运行 myprog 并显示警告和错误将类似于:

rustc myprog.rs
set RUST_LOG=myprog=4
myprog.exe

关于记录 Rust 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18433840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com