From cba16a0083ef553faf710223ea2fa785189e6742 Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Sat, 30 Dec 2017 18:43:46 +0800 Subject: [PATCH] Updated dependencies and made logging more readable --- Cargo.toml | 13 +++++++------ src/bin/mdbook.rs | 26 +++++++++++++++++--------- src/book/mod.rs | 2 +- src/book/summary.rs | 2 -- tests/parse_existing_summary_files.rs | 2 +- tests/rendered_output.rs | 2 +- 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e118bb13..f591afb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,15 +16,16 @@ exclude = [ [dependencies] clap = "2.24" +chrono = "0.4" handlebars = "0.29" serde = "1.0" serde_derive = "1.0" error-chain = "0.11.0" serde_json = "1.0" pulldown-cmark = "0.1" -lazy_static = "0.2" -log = "0.3" -env_logger = "0.4.0" +lazy_static = "1.0" +log = "0.4" +env_logger = "0.5.0-rc.1" toml = "0.4" memchr = "2.0.1" open = "1.1" @@ -37,8 +38,8 @@ time = { version = "0.1.34", optional = true } crossbeam = { version = "0.3", optional = true } # Serve feature -iron = { version = "0.5", optional = true } -staticfile = { version = "0.4", optional = true } +iron = { version = "0.6", optional = true } +staticfile = { version = "0.5", optional = true } ws = { version = "0.7", optional = true} [build-dependencies] @@ -47,7 +48,7 @@ error-chain = "0.11" [dev-dependencies] select = "0.4" pretty_assertions = "0.4" -walkdir = "1.0" +walkdir = "2.0" [features] default = ["output", "watch", "serve"] diff --git a/src/bin/mdbook.rs b/src/bin/mdbook.rs index 4d7fbd6b..305f9f94 100644 --- a/src/bin/mdbook.rs +++ b/src/bin/mdbook.rs @@ -1,5 +1,6 @@ #[macro_use] extern crate clap; +extern crate chrono; extern crate env_logger; extern crate error_chain; extern crate log; @@ -9,9 +10,11 @@ extern crate open; use std::env; use std::ffi::OsStr; use std::path::{Path, PathBuf}; +use std::io::Write; use clap::{App, AppSettings, ArgMatches}; -use log::{LogLevelFilter, LogRecord}; -use env_logger::LogBuilder; +use chrono::Local; +use log::LevelFilter; +use env_logger::Builder; use error_chain::ChainedError; pub mod build; @@ -67,19 +70,24 @@ 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 = Builder::new(); - let mut builder = LogBuilder::new(); - builder.format(format).filter(None, LogLevelFilter::Info); + builder.format(|formatter, record| { + writeln!(formatter, "{} [{}] ({}): {}", + Local::now().format("%Y-%m-%d %H:%M:%S"), + record.level(), + record.target(), + record.args()) + }); if let Ok(var) = env::var("RUST_LOG") { builder.parse(&var); + } else { + // if no RUST_LOG provided, default to logging at the Info level + builder.filter(None, LevelFilter::Info); } - builder.init().unwrap(); + builder.init(); } fn get_book_dir(args: &ArgMatches) -> PathBuf { diff --git a/src/book/mod.rs b/src/book/mod.rs index 92b409b7..bc8550e2 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -64,7 +64,7 @@ impl MDBook { Config::default() }; - if log_enabled!(::log::LogLevel::Trace) { + if log_enabled!(::log::Level::Trace) { for line in format!("Config: {:#?}", config).lines() { trace!("{}", line); } diff --git a/src/book/summary.rs b/src/book/summary.rs index 8e3daf68..4f2d1300 100644 --- a/src/book/summary.rs +++ b/src/book/summary.rs @@ -689,8 +689,6 @@ mod tests { /// [example]: https://github.com/rust-lang/book/blob/2c942dc094f4ddcdc7aba7564f80782801197c99/second-edition/src/SUMMARY.md#basic-rust-literacy #[test] fn can_have_a_subheader_between_nested_items() { - extern crate env_logger; - env_logger::init().ok(); let src = "- [First](./first.md)\n\n## Subheading\n\n- [Second](./second.md)\n"; let should_be = vec![ SummaryItem::Link(Link { diff --git a/tests/parse_existing_summary_files.rs b/tests/parse_existing_summary_files.rs index 1d963261..d489449a 100644 --- a/tests/parse_existing_summary_files.rs +++ b/tests/parse_existing_summary_files.rs @@ -14,7 +14,7 @@ macro_rules! summary_md_test { ($name:ident, $filename:expr) => { #[test] fn $name() { - env_logger::init().ok(); + env_logger::try_init().ok(); let filename = Path::new(env!("CARGO_MANIFEST_DIR")) .join("tests") diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs index 3dd16794..cff98899 100644 --- a/tests/rendered_output.rs +++ b/tests/rendered_output.rs @@ -11,7 +11,7 @@ use dummy_book::{assert_contains_strings, DummyBook}; use std::fs; use std::path::Path; use std::ffi::OsStr; -use walkdir::{DirEntry, WalkDir, WalkDirIterator}; +use walkdir::{DirEntry, WalkDir}; use select::document::Document; use select::predicate::{Class, Name, Predicate}; use mdbook::errors::*;