Better logging.
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -151,6 +151,14 @@ dependencies = [
|
|||||||
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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]]
|
[[package]]
|
||||||
name = "core-foundation"
|
name = "core-foundation"
|
||||||
version = "0.5.1"
|
version = "0.5.1"
|
||||||
@@ -306,6 +314,7 @@ name = "fern"
|
|||||||
version = "0.5.7"
|
version = "0.5.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
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)",
|
"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 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 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 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 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 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"
|
"checksum crc32fast 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e91d5240c6975ef33aeb5f148f35275c25eda8e8a5f95abe421978b05b8bf192"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ edition = "2018"
|
|||||||
bincode = "1.0"
|
bincode = "1.0"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
directories = "1.0"
|
directories = "1.0"
|
||||||
fern = "0.5"
|
fern = { version = "0.5", features = ["colored"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
regex = "1.1"
|
regex = "1.1"
|
||||||
reqwest = "0.9"
|
reqwest = "0.9"
|
||||||
|
|||||||
31
src/main.rs
31
src/main.rs
@@ -1,5 +1,6 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
use fern::colors::{Color, ColoredLevelConfig};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
mod context;
|
mod context;
|
||||||
@@ -11,6 +12,9 @@ use crate::probe::*;
|
|||||||
#[derive(Debug, StructOpt)]
|
#[derive(Debug, StructOpt)]
|
||||||
#[structopt(name = "whoareyou", about = "Search for swedish phone numbers.")]
|
#[structopt(name = "whoareyou", about = "Search for swedish phone numbers.")]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
|
#[structopt(short = "v", parse(from_occurrences))]
|
||||||
|
verbose: u8,
|
||||||
|
|
||||||
#[structopt(short = "o", long = "open")]
|
#[structopt(short = "o", long = "open")]
|
||||||
open: bool,
|
open: bool,
|
||||||
|
|
||||||
@@ -20,25 +24,38 @@ struct Opt {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
|
|
||||||
fern::Dispatch::new()
|
let colors = ColoredLevelConfig::new()
|
||||||
.format(|out, message, record| {
|
.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!(
|
out.finish(format_args!(
|
||||||
"{}[{}][{}] {}",
|
"{}[{}][{}] {}",
|
||||||
chrono::Local::now().format("[%Y-%m-%d %H:%M:%S]"),
|
chrono::Local::now().format("[%Y-%m-%d %H:%M:%S]"),
|
||||||
record.target(),
|
record.target(),
|
||||||
record.level(),
|
colors.color(record.level()),
|
||||||
message
|
message
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
.level(log::LevelFilter::Off)
|
|
||||||
.level_for("reqwest", log::LevelFilter::Off)
|
.level_for("reqwest", log::LevelFilter::Off)
|
||||||
.level_for("hyper", log::LevelFilter::Off)
|
.level_for("hyper", log::LevelFilter::Off)
|
||||||
.level_for("tokio_reactor", log::LevelFilter::Off)
|
.level_for("tokio_reactor", log::LevelFilter::Off)
|
||||||
.level_for("html5ever", log::LevelFilter::Off)
|
.level_for("html5ever", log::LevelFilter::Off)
|
||||||
.level_for("selectors", log::LevelFilter::Off)
|
.level_for("selectors", log::LevelFilter::Off)
|
||||||
.chain(std::io::stdout())
|
.chain(std::io::stdout());
|
||||||
.apply()
|
|
||||||
.expect("failed to init fern");
|
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<Box<Probe>> = vec![
|
let mut probes: Vec<Box<Probe>> = vec![
|
||||||
Box::new(Eniro),
|
Box::new(Eniro),
|
||||||
|
|||||||
Reference in New Issue
Block a user