If we have following code
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")
}
How do we enable the debug level output on Windows?
The log create is the de-facto logging API in Rust. There are five log levels: error (highest priority), warn, info, debug, and trace (lowest priority). To log a message, you use the corresponding logging marcos: error!, warn!, etc. These marcos behave like println! and supports the syntax of format!.
When executing your program, you need to set the RUST_LOG
environment variable appropriately; it is (as far as this is concerned) a comma-separated key=value list; the keys are crate or module names, e.g. extra
or std::option
; the values are numbers, mapped to log levels:
(Each level includes the more significant levels.)
In Command Prompt, compiling and running myprog
with showing warnings and errors would be something like:
rustc myprog.rs
set RUST_LOG=myprog=4
myprog.exe
You can set the logging level in the program by setting them to your environment as well. The statement you have to write is:
RUST_LOG=YOUR-PROJECT-NAME=log_level
eg:
RUST_LOG=Hello-World=info
or RUST_LOG=Hello-World=3
After setting your log level the next step is to initialize them by using 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