pretty_flexible_env_logger 0.1.0

A visually pretty yet a bit configurable env_logger
Documentation
  • Coverage
  • 100%
    11 out of 11 items documented1 out of 11 items with examples
  • Size
  • Source code size: 21.6 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.76 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 21s Average build duration of successful builds.
  • all releases: 21s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • unjello

pretty-flexible-env-logger

Crates.io Docs CC0-1.0 GitHub CI

A simple logger built on top of pretty_env_logger. An upstream's design decision was not to allow run-time configuration, but I have found that for CLI tools it actually makes sense to control logging in runtime based on command-line params, rather than requiring users to set RUST_LOG directly.

To keep things simple, init_with tries to look up passed string as an environment variable, and if that fails it considers the value to be inlined configuration, same as you would set RUST_LOG with.

let args: Vec<String> = env::args().collect();
let default = "RUST_LOG".to_string();
let level = args.get(1).unwrap_or(&default);
if let Err(e) = pretty_flexible_env_logger::try_init_with(level) {
    eprintln!("Some custom msg {}", e);
    panic!("error!") // or whatever
}

info!("info");
warn!("warn");
error!("error");
debug!("debug");

License

Related Work

This crate is a little contribution built on the shoulders of giants: