Follow these steps:
-
Open the Cargo.toml file that has been generated earlier for you.
-
Under [dependencies], add the following line:
log = "0.4.1"
env_logger = "0.5.3"
- If you want, you can go to log's (https://crates.io/crates/log) or env_logger's (https://crates.io/crates/env_log) crates.io pages to check for the newest version and use that one instead.
- In the folder bin, create a file called logging.rs.
-
Add the following code and run it with RUST_LOG=logging cargo run --bin logging if you're on a Unix-based system. Otherwise, run $env:RUST_LOG="logging"; cargo run --bin logging on Windows:
1 extern crate env_logger;
2 #[macro_use]
3 extern crate log;
4 use log::Level;
5
6 fn main() {
7 // env_logger's priority levels are:
8 // error > warn > info > debug > trace
9 env_logger::init();
10 // All logging calls log! in the background
11 log!(Level::Debug, "env_logger has been initialized...