RUST_LOG

Compile this example. To run it with an activated logger, you have to set the RUST_LOG environment variable. The env_logger crate reads it and configures the logger using filters from this variable. A logger instance must be configured with a corresponding logging level.

You can set the RUST_LOG variable globally. If you use the Bash shell, you can set it in your .bashrc file.

You can set RUST_LOG temporarily before the cargo run command:

RUST_LOG=trace cargo run

However, this will also print a lot of cargo tool and compiler records, because the Rust compiler also uses the log crate for logging. You can exclude all records except for those of your program using filtering by name. You only need to use part of the target name, as follows:

 RUST_LOG=random_service=trace,warn cargo run

This value of the RUST_LOG variable filters all records by the warn level and uses the trace level for targets starting with the random_service prefix.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.245.140