diff --git a/Cargo.lock b/Cargo.lock index 16e5ae0..b3808f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -151,6 +151,14 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "colored" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "core-foundation" version = "0.5.1" @@ -306,6 +314,7 @@ name = "fern" version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "colored 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1650,6 +1659,7 @@ dependencies = [ "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum colored 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6e9a455e156a4271e12fd0246238c380b1e223e3736663c7a18ed8b6362028a9" "checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980" "checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa" "checksum crc32fast 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e91d5240c6975ef33aeb5f148f35275c25eda8e8a5f95abe421978b05b8bf192" diff --git a/Cargo.toml b/Cargo.toml index 47a5429..33e2d23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" bincode = "1.0" chrono = { version = "0.4", features = ["serde"] } directories = "1.0" -fern = "0.5" +fern = { version = "0.5", features = ["colored"] } log = "0.4" regex = "1.1" reqwest = "0.9" diff --git a/src/main.rs b/src/main.rs index d8f8dc7..37360e9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use std::process::Command; +use fern::colors::{Color, ColoredLevelConfig}; use structopt::StructOpt; mod context; @@ -11,6 +12,9 @@ use crate::probe::*; #[derive(Debug, StructOpt)] #[structopt(name = "whoareyou", about = "Search for swedish phone numbers.")] struct Opt { + #[structopt(short = "v", parse(from_occurrences))] + verbose: u8, + #[structopt(short = "o", long = "open")] open: bool, @@ -20,25 +24,38 @@ struct Opt { fn main() { let opt = Opt::from_args(); - fern::Dispatch::new() - .format(|out, message, record| { + let colors = ColoredLevelConfig::new() + .error(Color::Red) + .warn(Color::Yellow) + .info(Color::White) + .debug(Color::White) + .trace(Color::BrightBlack); + + let mut config = fern::Dispatch::new() + .format(move |out, message, record| { out.finish(format_args!( "{}[{}][{}] {}", chrono::Local::now().format("[%Y-%m-%d %H:%M:%S]"), record.target(), - record.level(), + colors.color(record.level()), message )) }) - .level(log::LevelFilter::Off) .level_for("reqwest", log::LevelFilter::Off) .level_for("hyper", log::LevelFilter::Off) .level_for("tokio_reactor", log::LevelFilter::Off) .level_for("html5ever", log::LevelFilter::Off) .level_for("selectors", log::LevelFilter::Off) - .chain(std::io::stdout()) - .apply() - .expect("failed to init fern"); + .chain(std::io::stdout()); + + config = match opt.verbose { + 0 => config.level(log::LevelFilter::Info), + 1 => config.level(log::LevelFilter::Debug), + 2 => config.level(log::LevelFilter::Debug), + _ => config.level(log::LevelFilter::Trace), + }; + + config.apply().expect("failed to init fern"); let mut probes: Vec> = vec![ Box::new(Eniro),