简体   繁体   中英

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. 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. 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:

RUST_LOG="trace" cargo run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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