mirror of
https://github.com/XAMPPRocky/tokei
synced 2024-08-28 03:39:37 +00:00
Changed logging behaviour based on feedback.
This commit is contained in:
parent
2e5c46d71a
commit
1839132aa5
|
@ -374,7 +374,7 @@ impl LanguageType {
|
|||
"yaml" | "yml" => Some(Yaml),
|
||||
"zsh" => Some(Zsh),
|
||||
extension => {
|
||||
info!("Unknown extension: {}", extension);
|
||||
warn!("Unknown extension: {}", extension);
|
||||
None
|
||||
},
|
||||
}
|
||||
|
|
|
@ -49,12 +49,12 @@ fn count_files(mut language_tuple: (&LanguageType, &mut Language)) {
|
|||
let mut quote;
|
||||
|
||||
for file in files {
|
||||
let mut stats = Stats::new(opt_warn!(file.to_str(), "Couldn't convert path to String."));
|
||||
let mut stats = Stats::new(opt_error!(file.to_str(), "Couldn't convert path to String."));
|
||||
stack.clear();
|
||||
contents.clear();
|
||||
quote = None;
|
||||
|
||||
rs_warn!(rs_warn!(File::open(file)).read_to_end(&mut contents));
|
||||
rs_error!(rs_error!(File::open(file)).read_to_end(&mut contents));
|
||||
|
||||
|
||||
let text = match encoding::decode(&contents, DecoderTrap::Replace, encoding::all::UTF_8) {
|
||||
|
|
|
@ -17,7 +17,7 @@ use language::LanguageType::*;
|
|||
macro_rules! get_language {
|
||||
($languages:expr, $entry:expr) => {
|
||||
if let Some(language_type) = LanguageType::from_extension($entry) {
|
||||
opt_warn!($languages.get_mut(&language_type), "Unknown Language? Shouldn't happen.")
|
||||
opt_error!($languages.get_mut(&language_type), "Unknown Language? Shouldn't happen.")
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ pub fn get_all_files<'a>(paths: Cow<'a, [&'a str]>,
|
|||
if let Err(_) = Path::new(path).metadata() {
|
||||
if let Ok(paths) = glob(path) {
|
||||
'path: for path in paths {
|
||||
let path = rs_warn!(path);
|
||||
let path_str = opt_warn!(path.to_str(),
|
||||
let path = rs_error!(path);
|
||||
let path_str = opt_error!(path.to_str(),
|
||||
"DURING FILE LOOKUP: Couldn't convert path to string.");
|
||||
|
||||
for ig in &*ignored_directories {
|
||||
|
@ -63,9 +63,9 @@ pub fn get_all_files<'a>(paths: Cow<'a, [&'a str]>,
|
|||
});
|
||||
|
||||
for entry in walker {
|
||||
let entry = rs_warn!(entry);
|
||||
let entry = rs_error!(entry);
|
||||
|
||||
let mut language = if opt_warn!(entry.path().to_str(),
|
||||
let mut language = if opt_error!(entry.path().to_str(),
|
||||
"Walkdir: Couldn't convert path to string")
|
||||
.contains("Makefile") {
|
||||
languages.get_mut(&Makefile).unwrap()
|
||||
|
@ -119,7 +119,7 @@ pub fn get_filetype_from_shebang<P: AsRef<Path>>(file: P) -> Option<&'static str
|
|||
Some("python") | Some("python2") | Some("python3") => Some("py"),
|
||||
Some("sh") => Some("sh"),
|
||||
env => {
|
||||
info!("Unknown environment: {:?}", env);
|
||||
warn!("Unknown environment: {:?}", env);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,31 +2,6 @@
|
|||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
macro_rules! opt_info {
|
||||
($option:expr, $message:expr) => {
|
||||
match $option {
|
||||
Some(result) => result,
|
||||
None => {
|
||||
info!($message);
|
||||
continue;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! rs_info {
|
||||
($result:expr, $message: expr) => {
|
||||
match $result {
|
||||
Ok(result) => result,
|
||||
Err(error) => {
|
||||
use std::error::Error;
|
||||
info!("{}", error.description());
|
||||
continue;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! opt_warn {
|
||||
($option:expr, $message:expr) => {
|
||||
match $option {
|
||||
|
@ -40,7 +15,7 @@ macro_rules! opt_warn {
|
|||
}
|
||||
|
||||
macro_rules! rs_warn {
|
||||
($result:expr) => {
|
||||
($result:expr, $message: expr) => {
|
||||
match $result {
|
||||
Ok(result) => result,
|
||||
Err(error) => {
|
||||
|
@ -52,6 +27,31 @@ macro_rules! rs_warn {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! opt_error {
|
||||
($option:expr, $message:expr) => {
|
||||
match $option {
|
||||
Some(result) => result,
|
||||
None => {
|
||||
error!($message);
|
||||
continue;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! rs_error {
|
||||
($result:expr) => {
|
||||
match $result {
|
||||
Ok(result) => result,
|
||||
Err(error) => {
|
||||
use std::error::Error;
|
||||
error!("{}", error.description());
|
||||
continue;
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
macro_rules! debug {
|
||||
($fmt:expr) => (if cfg!(debug_assertions) {println!($fmt)});
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -67,20 +67,16 @@ fn main() {
|
|||
}
|
||||
ignored_directories
|
||||
};
|
||||
|
||||
if verbose_option != 0 {
|
||||
let mut builder = LogBuilder::new();
|
||||
match verbose_option {
|
||||
1 => {
|
||||
builder.filter(None, LogLevelFilter::Warn);
|
||||
}
|
||||
2 => {
|
||||
builder.filter(None, LogLevelFilter::Info);
|
||||
}
|
||||
_ => {/* NOOP */}
|
||||
let mut builder = LogBuilder::new();
|
||||
match verbose_option {
|
||||
1 => {
|
||||
builder.filter(None, LogLevelFilter::Warn);
|
||||
}
|
||||
_ => {
|
||||
builder.filter(None, LogLevelFilter::Error);
|
||||
}
|
||||
builder.init().unwrap();
|
||||
}
|
||||
builder.init().unwrap();
|
||||
|
||||
let mut languages = Languages::new();
|
||||
|
||||
|
|
Loading…
Reference in a new issue