Increased default logging level to info unless RUST_LOG is set
This commit is contained in:
parent
a220528c15
commit
287f539b7d
|
@ -10,6 +10,8 @@ use std::ffi::OsStr;
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use clap::{App, ArgMatches, AppSettings};
|
use clap::{App, ArgMatches, AppSettings};
|
||||||
|
use log::{LogRecord, LogLevelFilter};
|
||||||
|
use env_logger::LogBuilder;
|
||||||
|
|
||||||
pub mod build;
|
pub mod build;
|
||||||
pub mod init;
|
pub mod init;
|
||||||
|
@ -22,7 +24,7 @@ pub mod watch;
|
||||||
const NAME: &'static str = "mdbook";
|
const NAME: &'static str = "mdbook";
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init().unwrap();
|
init_logger();
|
||||||
|
|
||||||
// Create a list of valid arguments and sub-commands
|
// Create a list of valid arguments and sub-commands
|
||||||
let app = App::new(NAME)
|
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 {
|
fn get_book_dir(args: &ArgMatches) -> PathBuf {
|
||||||
if let Some(dir) = args.value_of("dir") {
|
if let Some(dir) = args.value_of("dir") {
|
||||||
// Check if path is relative from current dir, or absolute...
|
// Check if path is relative from current dir, or absolute...
|
||||||
|
|
Loading…
Reference in New Issue