diff options
author | Sascha Grunert <Sascha.Grunert@rohde-schwarz.com> | 2016-12-22 18:35:20 +0100 |
---|---|---|
committer | Sascha Grunert <Sascha.Grunert@rohde-schwarz.com> | 2016-12-22 18:35:26 +0100 |
commit | a17a385e496992fed3bfcfdcbfaebbf25e615ef6 (patch) | |
tree | 390b01acda6a2765b41c14f38981ce17728e0ba3 | |
parent | 4ca12b772a5b39d75889b4466fff5d671a1a86dc (diff) |
Changed to mowl dependency for logging
-rw-r--r-- | Cargo.lock | 12 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/lib.rs | 11 | ||||
-rw-r--r-- | src/logger.rs | 59 |
4 files changed, 15 insertions, 68 deletions
@@ -7,11 +7,11 @@ dependencies = [ "git2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "mowl 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "nom 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.21 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -199,6 +199,15 @@ dependencies = [ ] [[package]] +name = "mowl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "nom" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -456,6 +465,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054" "checksum matches 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "efd7622e3022e1a6eaa602c4cea8912254e5582c9c692e9167714182244801b1" "checksum memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d8b629fb514376c675b98c1421e80b151d3817ac42d7c667717d282761418d20" +"checksum mowl 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c2eaf9bae72d1d94500cdec34622cae809a409509324b50851ada136b8d6f58f" "checksum nom 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ffc564b2727f758993db55d4ffed0d84bbd7f387a66509516768c8f786bb0b10" "checksum num 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "bde7c03b09e7c6a301ee81f6ddf66d7a28ec305699e3d3b056d2fc56470e3120" "checksum num-integer 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "fb24d9bfb3f222010df27995441ded1e954f8f69cd35021f6bef02ca9552fb92" @@ -19,6 +19,7 @@ clap = { version = "2", features = ["yaml"] } git2 = "0" lazy_static = "0" log = "0" +mowl = "1" nom = { version = "2", features = ["regexp_macros"] } regex = "0" rayon = "0" @@ -27,6 +27,7 @@ extern crate regex; extern crate rustc_serialize; extern crate term; extern crate toml; +extern crate mowl; #[macro_use] extern crate nom; @@ -45,18 +46,16 @@ use std::{env, fs}; use chrono::{UTC, TimeZone}; use git2::{ObjectType, Oid, Repository}; -use log::LogLevelFilter; +use log::LogLevel; use rayon::prelude::*; use toml::Value; pub use config::Config; pub use errors::{GitJournalResult, error}; -use logger::Logger; use parser::{Parser, ParsedTag, Tags}; #[macro_use] mod errors; -mod logger; mod parser; pub mod config; @@ -87,11 +86,7 @@ impl GitJournal { /// pub fn new(path: &str) -> GitJournalResult<Self> { // Setup the logger if not already set - if log::set_logger(|max_log_level| { - max_log_level.set(LogLevelFilter::Info); - Box::new(Logger) - }) - .is_err() { + if mowl::init_with_level(LogLevel::Info).is_err() { warn!("Logger already set."); }; diff --git a/src/logger.rs b/src/logger.rs deleted file mode 100644 index 27aa6b9..0000000 --- a/src/logger.rs +++ /dev/null @@ -1,59 +0,0 @@ -//! The logger implementation -use log::{Log, LogRecord, LogLevel, LogMetadata}; - -use term::stderr; -use term::color::{BRIGHT_BLUE, GREEN, BRIGHT_YELLOW, RED}; - -use errors::{GitJournalResult, error}; - -/// The logging structure -pub struct Logger; - -impl Log for Logger { - fn enabled(&self, metadata: &LogMetadata) -> bool { - metadata.level() <= LogLevel::Info - } - - fn log(&self, record: &LogRecord) { - if self.enabled(record.metadata()) { - if let Err(e) = self.log_result(record) { - println!("Error printing to log: {}", e); - } - } - } -} - -impl Logger { - fn log_result(&self, record: &LogRecord) -> GitJournalResult<()> { - // We have to create a new terminal on each log because - // `term::Terminal<Output=std::io::Stderr> + Send + 'static` cannot be shared between - // threads safely' - let mut t = stderr().ok_or(error("Term", "Could not create terminal"))?; - t.fg(BRIGHT_BLUE)?; - write!(t, "[git-journal] ")?; - match record.level() { - LogLevel::Info => { - t.fg(GREEN)?; - write!(t, "[OKAY] ")?; - t.reset()?; - writeln!(t, "{}", record.args())?; - } - LogLevel::Warn => { - t.fg(BRIGHT_YELLOW)?; - write!(t, "[WARN] ")?; - t.reset()?; - writeln!(t, "{}", record.args())?; - } - LogLevel::Error => { - t.fg(RED)?; - write!(t, "[ERROR] ")?; - t.reset()?; - writeln!(t, "{}", record.args())?; - } - _ => { - writeln!(t, "[{}] {}", record.level(), record.args())?; - } - } - Ok(()) - } -} |