mirror of
https://github.com/Skallwar/suckit.git
synced 2026-09-10 07:16:19 -04:00
scraper: Use logger, add --quiet option
This commit is contained in:
parent
debe1eca64
commit
2b84cb165a
|
|
@ -19,6 +19,9 @@ pub struct Args {
|
|||
|
||||
#[structopt(short, long, default_value = "20")]
|
||||
pub tries: usize,
|
||||
|
||||
#[structopt(short, long)]
|
||||
pub quiet: bool,
|
||||
}
|
||||
|
||||
impl Args {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ static TIME_FORMAT: &str = "%Y-%m-%dT%H:%M:%S";
|
|||
pub struct Logger {
|
||||
}
|
||||
|
||||
// Allow the dead code in case we don't use all the macros. Using it here means
|
||||
// it doesn't affect the other modules in the crate
|
||||
#[allow(dead_code)]
|
||||
impl Logger {
|
||||
/// Get the current formatted timestamp
|
||||
fn get_timestamp() -> String {
|
||||
|
|
@ -36,16 +39,19 @@ impl Logger {
|
|||
}
|
||||
|
||||
#[macro_export]
|
||||
/// Print an info message on stdout
|
||||
macro_rules! info {
|
||||
($($arg: tt)*) => ($crate::logger::Logger::info(format!($($arg)*)));
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
/// Print a warning message on stdout
|
||||
macro_rules! warn {
|
||||
($($arg: tt)*) => ($crate::logger::Logger::warn(format!($($arg)*)));
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
/// Print an error message on stderr
|
||||
macro_rules! error {
|
||||
($($arg: tt)*) => ($crate::logger::Logger::error(format!($($arg)*)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ use super::args;
|
|||
use super::disk;
|
||||
use super::dom;
|
||||
|
||||
use crate::info;
|
||||
|
||||
/// Maximum number of empty recv() from the channel
|
||||
static MAX_EMPTY_RECEIVES: usize = 10;
|
||||
|
||||
|
|
@ -108,7 +110,9 @@ impl Scraper {
|
|||
|
||||
scraper.visited_urls.lock().unwrap().insert(url.to_string());
|
||||
|
||||
println!("{} has been downloaded", url);
|
||||
if !scraper.args.quiet {
|
||||
info!("Downloaded {}", url);
|
||||
}
|
||||
}
|
||||
|
||||
/// Run through the channel and complete it
|
||||
|
|
|
|||
Loading…
Reference in a new issue