I'm developing a project in Rust that is meant to be used by systems administrators, via CLI. In this program, I would like to have lines like these:
warn!("File {} not found, proceeding to next file", file_path);
Which I don't consider errors in the context of the software, but I still would want my users to be aware of.
However, Rust's logging system, by default, only prints messages on the ERROR log level, and the only way I found to change this default is to set the RUST_LOG environment variable - which I don't want my users to have to do. I guess I could create a wrapper script that just sets the variable and execs the program, but I would rather not.
Is there a way to change the default level programmatically, from inside the program?
Here's a trick which will make it
if env::var("RUST_LOG").is_err() {
env::set_var("RUST_LOG", "info")
}
env_logger::init();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With