简体   繁体   English

如何在 Rust 上记录所有内容或如何记录多个内容?

[英]How to log everything on Rust or how to log more than one thing?

I couldn't find easy information about how to log properly on Rust.我找不到有关如何正确登录 Rust 的简单信息。 I'm doing like this:我正在这样做:

use log::{debug, error, info, warn};

fn main() {
    env_logger::init();
    info!("test info");
    error!("test error");
}

How do I activate both info and error?如何激活信息和错误?

RUST_LOG="info,error" cargo run

won't activate both (none of them get activated), but不会同时激活(它们都不会被激活),但是

RUST_LOG="info" cargo run

works.作品。

Also, how to activate everything?另外,如何激活一切?

The log levels are hierarchical, meaning that if you set the level to info , info messages and all levels above it will be captured.日志级别是分层的,这意味着如果您将级别设置为info ,则会捕获info消息和高于它的所有级别。 Only messages with a lower priority than the enabled level are filtered out:仅过滤掉优先级低于启用级别的消息:

  • error
  • warn
  • info
  • debug
  • trace

Being the lowest level, trace will capture all logs:作为最低级别, trace将捕获所有日志:

RUST_LOG="trace" cargo run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM