From 287f539b7dd57620bd97cbfa0f63b46944cc60e7 Mon Sep 17 00:00:00 2001 From: Michal Budzynski Date: Wed, 28 Jun 2017 23:37:03 +0200 Subject: [PATCH] Increased default logging level to info unless RUST_LOG is set --- src/bin/mdbook.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/bin/mdbook.rs b/src/bin/mdbook.rs index 43fa0212..84503800 100644 --- a/src/bin/mdbook.rs +++ b/src/bin/mdbook.rs @@ -10,6 +10,8 @@ use std::ffi::OsStr; use std::io::{self, Write}; use std::path::{Path, PathBuf}; use clap::{App, ArgMatches, AppSettings}; +use log::{LogRecord, LogLevelFilter}; +use env_logger::LogBuilder; pub mod build; pub mod init; @@ -22,7 +24,7 @@ pub mod watch; const NAME: &'static str = "mdbook"; fn main() { - env_logger::init().unwrap(); + init_logger(); // Create a list of valid arguments and sub-commands let app = App::new(NAME) @@ -59,6 +61,22 @@ fn main() { } } +fn init_logger() { + let format = |record: &LogRecord| { + let module_path = record.location().module_path(); + format!("{}:{}: {}", record.level(), module_path, record.args()) + }; + + let mut builder = LogBuilder::new(); + builder.format(format).filter(None, LogLevelFilter::Info); + + if let Ok(var) = env::var("RUST_LOG") { + builder.parse(&var); + } + + builder.init().unwrap(); +} + fn get_book_dir(args: &ArgMatches) -> PathBuf { if let Some(dir) = args.value_of("dir") { // Check if path is relative from current dir, or absolute...