January 2019
Beginner to intermediate
554 pages
13h 31m
English
The log4rs crate, as the name suggests, is inspired by the popular log4j library from Java. This crate is much more powerful than env_logger and allows for granular logger configuration via YAML files.
We'll build two crates to demonstrate integrating logging via the log4rs crate. One will be a library crate, cargo new my_lib --lib, and the other will be our binary crate, cargo new my_app, which uses my_lib. A cargo workspace directory, called log4rs_demo, contains both of our crates.
Our my_lib crate has the following contents in the lib.rs file:
// log4rs_demo/my_lib/lib.rsuse log::debug;pub struct Config;impl Config { pub fn load_global_config() { debug!("Configuration files loaded"); }}
It has a struct called Config with a dummy ...
Read now
Unlock full access