Skip to content

Commit

Permalink
feat: Log debug information
Browse files Browse the repository at this point in the history
Fixes #39
  • Loading branch information
epage committed Jul 20, 2019
1 parent 2c7dc55 commit 469ae14
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
75 changes: 75 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ iterate_unstable = []
failure = "0.1"
structopt = "0.2"
clap = "2"
clap-verbosity-flag = "0.2.0"
ignore = "0.4"
phf = { version = "0.7", features = ["unicase"] }
regex = "1.0"
Expand All @@ -33,6 +34,8 @@ serde_json = "1.0"
itertools = "0.8"
unicase = "1.1"
bstr = "0.2"
log = "0.4"
env_logger = "0.6"

[dev-dependencies]
assert_fs = "0.10"
Expand Down
29 changes: 29 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#[macro_use]
extern crate clap;

use std::io::Write;

use structopt::StructOpt;

arg_enum! {
Expand Down Expand Up @@ -124,6 +126,9 @@ struct Options {
no_ignore_vcs: bool,
#[structopt(long, raw(overrides_with = r#""no-ignore-vcs""#), raw(hidden = "true"))]
ignore_vcs: bool,

#[structopt(flatten)]
verbose: clap_verbosity_flag::Verbosity,
}

impl Options {
Expand Down Expand Up @@ -231,9 +236,33 @@ impl Options {
}
}

pub fn get_logging(level: log::Level) -> env_logger::Builder {
let mut builder = env_logger::Builder::new();

builder.filter(None, level.to_level_filter());

if level == log::LevelFilter::Trace {
builder.default_format_timestamp(false);
} else {
builder.format(|f, record| {
writeln!(
f,
"[{}] {}",
record.level().to_string().to_lowercase(),
record.args()
)
});
}

builder
}

fn run() -> Result<(), failure::Error> {
let options = Options::from_args().infer();

let mut builder = get_logging(options.verbose.log_level());
builder.init();

let dictionary = typos::Dictionary::new();
let check_filenames = options.check_filenames().unwrap_or(true);
let check_files = options.check_files().unwrap_or(true);
Expand Down

0 comments on commit 469ae14

Please sign in to comment.