Skip to content

Instantly share code, notes, and snippets.

@jonas-schievink
Last active November 30, 2018 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonas-schievink/70337487b05ca63fc4d64f44d972829c to your computer and use it in GitHub Desktop.
Save jonas-schievink/70337487b05ca63fc4d64f44d972829c to your computer and use it in GitHub Desktop.
Default log level for (pretty_)env_logger
extern crate env_logger;
extern crate log;
use std::env;
fn main() {
// By default, log all `info!` messages and higher, in all modules and crates.
// Can be overridden by specifying the `RUST_LOG` environment variable.
if env::var_os("RUST_LOG").is_none() {
env_logger::Builder::from_default_env()
.filter(None, log::LevelFilter::Info)
.init();
} else {
env_logger::init();
}
info!("shows up without having to set RUST_LOG");
debug!("only shows up when RUST_LOG=debug is set");
// Or: Log *all levels* for the current crate (`module_path!()` will expand to the crate name)
if env::var_os("RUST_LOG").is_none() {
pretty_env_logger::formatted_builder()
.unwrap()
.filter(Some(module_path!()), log::LevelFilter::Trace)
.init();
} else {
pretty_env_logger::init();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment