diff --git a/proc_macros/proc_macros.rs b/proc_macros/proc_macros.rs index d2e6ca6..225d675 100644 --- a/proc_macros/proc_macros.rs +++ b/proc_macros/proc_macros.rs @@ -978,7 +978,7 @@ pub fn print_error(item: TokenStream) -> TokenStream { match (#expr) { Ok(re) => re, Err(e) => { - println!("{}{}", #msg, e); + log::error!("{}{}", #msg, e); return #re; } } diff --git a/src/cookies.rs b/src/cookies.rs index 84d492e..a3edbe0 100644 --- a/src/cookies.rs +++ b/src/cookies.rs @@ -76,7 +76,7 @@ impl Cookie { let mut expired: i64 = 0; let u = url.into_url(); if u.is_err() { - println!( + log::warn!( "{} {}", gettext("Warning: Failed to parse URL:"), u.unwrap_err() @@ -91,7 +91,7 @@ impl Cookie { let t = String::from(m); let l2: Vec<&str> = t.split("=").collect(); if l2.len() < 2 { - println!( + log::warn!( "{} {}", gettext("Warning: Failed to parse cookie's key and value:"), m @@ -110,7 +110,7 @@ impl Cookie { let k = ll[0].to_lowercase(); if k == "expires" { if ll.len() < 2 { - println!("{}", gettext("Warning: Expires need a date.")); + log::warn!("{}", gettext("Warning: Expires need a date.")); return None; } let mut re = dateparser::parse(ll[1]); @@ -118,7 +118,7 @@ impl Cookie { let s = ll[1].replace("-", " "); re = dateparser::parse(s.as_str()); if re.is_err() { - println!( + log::warn!( "{} {}", gettext("Failed to parse UTC string:"), re.unwrap_err() @@ -130,12 +130,12 @@ impl Cookie { expired = r.timestamp(); } else if k == "max-age" { if ll.len() < 2 { - println!("{}", gettext("Warning: Max-Age need a duration.")); + log::warn!("{}", gettext("Warning: Max-Age need a duration.")); return None; } let re = ll[1].parse::(); if re.is_err() { - println!( + log::warn!( "{} {}", gettext("Failed to parse Max-Age:"), re.unwrap_err() @@ -145,18 +145,18 @@ impl Cookie { expired = re.unwrap() + Utc::now().timestamp(); } else if k == "domain" { if ll.len() < 2 { - println!("{}", gettext("Warning: Domain need a domain.")); + log::warn!("{}", gettext("Warning: Domain need a domain.")); return None; } domain = Some(String::from(ll[1])); } else if k == "path" { if ll.len() < 2 { - println!("{}", gettext("Warning: Path need a path.")); + log::warn!("{}", gettext("Warning: Path need a path.")); return None; } let p = ll[1].to_string(); if !p.starts_with("/") { - println!( + log::warn!( "{} {}", gettext("Warning: path is not starts with \"/\":"), p.as_str() @@ -171,7 +171,7 @@ impl Cookie { } } if domain.is_none() { - println!("{}", gettext("Warning: Failed to get domain.")); + log::warn!("{}", gettext("Warning: Failed to get domain.")); return None; } let domain = domain.unwrap(); @@ -221,7 +221,7 @@ impl Cookie { pub fn matched(&self, url: U) -> bool { let u = url.into_url(); if u.is_err() { - println!( + log::warn!( "{} {}", gettext("Warning: Failed to parse URL:"), u.unwrap_err() @@ -367,12 +367,12 @@ impl CookieJar { self.cookies.clear(); let p = file_name.as_ref(); if !p.exists() { - println!("{} {}", gettext("Can not find file:"), p.display()); + log::error!("{} {}", gettext("Can not find file:"), p.display()); return false; } let re = File::open(p); if re.is_err() { - println!("{} {}", gettext("Can not open file:"), p.display()); + log::error!("{} {}", gettext("Can not open file:"), p.display()); return false; } let f = re.unwrap(); @@ -386,7 +386,7 @@ impl CookieJar { } let mut s = l.split('\t'); if s.clone().count() < 7 { - println!("{} {}", gettext("Invalid cookie:"), l); + log::error!("{} {}", gettext("Invalid cookie:"), l); return false; } let domain = s.next().unwrap(); @@ -398,7 +398,7 @@ impl CookieJar { let value = s.next().unwrap(); let tmp = expired.trim().parse::(); if tmp.is_err() { - println!("{} {}", gettext("Can not parse expired time:"), expired); + log::error!("{} {}", gettext("Can not parse expired time:"), expired); return false; } let tmp = tmp.unwrap(); @@ -423,20 +423,20 @@ impl CookieJar { if p.exists() { let re = remove_file(p); if re.is_err() { - println!("{} {}", gettext("Failed to remove file:"), re.unwrap_err()); + log::error!("{} {}", gettext("Failed to remove file:"), re.unwrap_err()); return false; } } let re = File::create(p); if re.is_err() { - println!("{} {}", gettext("Failed to create file:"), re.unwrap_err()); + log::error!("{} {}", gettext("Failed to create file:"), re.unwrap_err()); return false; } let mut f = re.unwrap(); for c in self.cookies.iter() { let r = write!(f, "{}", c.to_netscape_str().as_str()); if r.is_err() { - println!("{} {}", gettext("Failed to write file:"), r.unwrap_err()); + log::error!("{} {}", gettext("Failed to write file:"), r.unwrap_err()); return false; } } @@ -517,7 +517,7 @@ impl CookieJarManager { *count -= 1; if *count == 0 { if !jar.get_mut().save(&path) { - println!( + log::warn!( "{} {}", gettext("Warning: Failed to save cookies file:"), path.display() diff --git a/src/data/data.rs b/src/data/data.rs index b8845b5..5d047de 100644 --- a/src/data/data.rs +++ b/src/data/data.rs @@ -128,7 +128,7 @@ impl PixivData { self.description = Some(s); } Err(s) => { - println!("{} {}", gettext("Failed to unescape string:"), s.as_str()); + log::warn!("{} {}", gettext("Failed to unescape string:"), s.as_str()); } } } diff --git a/src/data/json.rs b/src/data/json.rs index 93e2899..f084164 100644 --- a/src/data/json.rs +++ b/src/data/json.rs @@ -45,7 +45,7 @@ impl JSONDataFile { if p.exists() { let r = remove_file(p); if r.is_err() { - println!("{} {}", gettext("Failed to remove file:"), r.unwrap_err()); + log::error!("{} {}", gettext("Failed to remove file:"), r.unwrap_err()); return false; } } @@ -56,13 +56,13 @@ impl JSONDataFile { let value = value.unwrap(); let f = File::create(p); if f.is_err() { - println!("{} {}", gettext("Failed to create file:"), f.unwrap_err()); + log::error!("{} {}", gettext("Failed to create file:"), f.unwrap_err()); return false; } let mut f = f.unwrap(); let r = f.write(value.pretty(2).as_bytes()); if r.is_err() { - println!("{} {}", gettext("Failed to write file:"), r.unwrap_err()); + log::error!("{} {}", gettext("Failed to write file:"), r.unwrap_err()); return false; } true diff --git a/src/download.rs b/src/download.rs index 50572c9..8279686 100644 --- a/src/download.rs +++ b/src/download.rs @@ -75,14 +75,14 @@ impl Main { if !fc.is_inited() { let helper = get_helper(); if !fc.init(helper.cookies()) { - println!("{}", gettext("Failed to initialize fanbox api client.")); + log::error!("{}", gettext("Failed to initialize fanbox api client.")); return 1; } if !fc.check_login().await { return 1; } if !fc.logined() { - println!("{}", gettext("Warning: Fanbox client is not logged in.")); + log::warn!("{}", gettext("Warning: Fanbox client is not logged in.")); } } tasks @@ -96,14 +96,14 @@ impl Main { if !fc.is_inited() { let helper = get_helper(); if !fc.init(helper.cookies()) { - println!("{}", gettext("Failed to initialize fanbox api client.")); + log::error!("{}", gettext("Failed to initialize fanbox api client.")); return 1; } if !fc.check_login().await { return 1; } if !fc.logined() { - println!("{}", gettext("Warning: Fanbox client is not logged in.")); + log::warn!("{}", gettext("Warning: Fanbox client is not logged in.")); } } tasks @@ -131,7 +131,7 @@ impl Main { match result { Ok(_) => {} Err(e) => { - println!("{} {}", gettext("Failed to download post:"), e); + log::error!("{} {}", gettext("Failed to download post:"), e); re = 1; } } @@ -174,7 +174,7 @@ impl Main { match result { Ok(_) => {} Err(e) => { - println!("{} {}", gettext("Failed to download url:"), e); + log::error!("{} {}", gettext("Failed to download url:"), e); re = 1; } } @@ -218,7 +218,7 @@ pub async fn download_artwork_link( #[cfg(feature = "exif")] { if add_exifdata_to_image(&file_name, &datas, np).is_err() { - println!( + log::warn!( "{} {}", gettext("Failed to add exif data to image:"), file_name.to_str().unwrap_or("(null)") @@ -237,7 +237,7 @@ pub async fn download_artwork_link( { if helper.update_exif() && file_name.exists() { if add_exifdata_to_image(&file_name, &datas, np).is_err() { - println!( + log::warn!( "{} {}", gettext("Failed to add exif data to image:"), file_name.to_str().unwrap_or("(null)") @@ -262,7 +262,7 @@ pub async fn download_artwork( if e.is_not_found() { return Err(e); } - println!("{}{}", gettext("Warning: Failed to download artwork with app api, trying to download with web api: "), e); + log::warn!("{}{}", gettext("Warning: Failed to download artwork with app api, trying to download with web api: "), e); download_artwork_web(pw.clone(), id).await?; } } else if app_ok { @@ -319,7 +319,7 @@ pub async fn download_artwork_ugoira( let metadata = match get_video_metadata(Arc::clone(&datas).as_ref()) { Ok(m) => m, Err(e) => { - println!( + log::warn!( "{} {}", gettext("Warning: Failed to generate video's metadata:"), e @@ -351,7 +351,7 @@ pub async fn download_artwork_ugoira( &options, &metadata, )?; - println!( + log::info!( "{}", gettext("Converted -> ") .replace("", file_name.to_str().unwrap_or("(null)")) @@ -398,7 +398,7 @@ pub async fn download_artwork_app( } if helper.add_history() && !web_used { if let Err(e) = ac.add_illust_to_browsing_history(vec![id]).await { - println!( + log::warn!( "{} {}", gettext("Warning: Failed to add artwork to history:"), e @@ -421,7 +421,7 @@ pub async fn download_artwork_app( _ => {} }, None => { - println!("{}", gettext("Warning: Failed to get illust's type.")); + log::warn!("{}", gettext("Warning: Failed to get illust's type.")); } } let page_count = data @@ -534,10 +534,10 @@ pub async fn download_artwork_web( ) -> Result<(), PixivDownloaderError> { if !pw.is_login_checked() { if !pw.check_login().await { - println!("{}", gettext("Failed to check login status.")); + log::error!("{}", gettext("Failed to check login status.")); } else { if !pw.logined() { - println!( + log::warn!( "{}", gettext("Warning: Web api client not logged in, some future may not work.") ); @@ -602,7 +602,7 @@ pub async fn download_artwork_web( return download_artwork_ugoira(pw, id, base, datas).await; } _ => { - println!( + log::warn!( "{} {}", gettext("Warning: Unknown illust type:"), illust_type @@ -610,7 +610,7 @@ pub async fn download_artwork_web( } } } else { - println!("{}", gettext("Warning: Failed to get illust's type.")); + log::warn!("{}", gettext("Warning: Failed to get illust's type.")); } if pages_data.is_some() && helper.download_multiple_files() { let mut np = 0u16; @@ -791,7 +791,7 @@ pub async fn download_fanbox_image( #[cfg(feature = "exif")] { if add_exifdata_to_image(&file_name, &datas, np).is_err() { - println!( + log::warn!( "{} {}", gettext("Failed to add exif data to image:"), file_name.to_str().unwrap_or("(null)") @@ -810,7 +810,7 @@ pub async fn download_fanbox_image( { if helper.update_exif() && file_name.exists() { if add_exifdata_to_image(&file_name, &datas, np).is_err() { - println!( + log::warn!( "{} {}", gettext("Failed to add exif data to image:"), file_name.to_str().unwrap_or("(null)") @@ -1129,7 +1129,7 @@ pub async fn download_fanbox_creator_info( match data.check_unknown() { Ok(_) => {} Err(e) => { - println!( + log::warn!( "{} {}", gettext("Warning: Creator's info contains unknown data:"), e diff --git a/src/downloader/downloader.rs b/src/downloader/downloader.rs index 760a119..044ee8c 100644 --- a/src/downloader/downloader.rs +++ b/src/downloader/downloader.rs @@ -224,7 +224,7 @@ impl Dow pub fn enable_multiple_download(&self) { self.multi.qstore(true); if !self.is_multi_threads() { - println!( + log::warn!( "{}", gettext("Warning: This file will still use single thread mode to download.") ); @@ -232,7 +232,7 @@ impl Dow match self.pd.enable_multi() { Ok(_) => {} Err(e) => { - println!("{}", e); + log::error!("{}", e); } } } @@ -265,7 +265,7 @@ impl Dow match self.pd.disable_multi() { Ok(_) => {} Err(e) => { - println!("{}", e); + log::error!("{}", e); } }; } @@ -608,7 +608,7 @@ impl {} Err(e) => { - println!("{}", e); + log::error!("{}", e); } } } diff --git a/src/downloader/pd_file/file.rs b/src/downloader/pd_file/file.rs index 11ea188..6ff07a8 100644 --- a/src/downloader/pd_file/file.rs +++ b/src/downloader/pd_file/file.rs @@ -494,7 +494,7 @@ impl PdFile { match self.remove_pd_file() { Ok(_) => {} Err(e) => { - println!("{} {}", gettext("Failed to remove file: "), e); + log::error!("{} {}", gettext("Failed to remove file: "), e); } } } @@ -692,7 +692,7 @@ impl Drop for PdFile { match self.write() { Ok(_) => {} Err(e) => { - println!("{}", e); + log::error!("{}", e); self.force_close(); self.remove_pd_file_with_err_msg(); } diff --git a/src/downloader/tasks.rs b/src/downloader/tasks.rs index 5ee7792..fb54ae1 100644 --- a/src/downloader/tasks.rs +++ b/src/downloader/tasks.rs @@ -181,7 +181,7 @@ pub async fn create_download_tasks_multi_first< } } Err(e) => { - println!("{}", e) + log::error!("{}", e) } } if d.enabled_progress_bar() { @@ -199,7 +199,7 @@ pub async fn create_download_tasks_multi_first< match d.pd.initialize_part_datas() { Ok(_) => {} Err(e) => { - println!("{}", e); + log::error!("{}", e); } } if d.enabled_progress_bar() { @@ -436,7 +436,7 @@ pub async fn check_tasks< } } Err(e) => { - println!("{}", e); + log::error!("{}", e); if !d.is_multi_threads() { match d.get_retry_duration() { Some(d) => dur = Some(d), @@ -506,7 +506,7 @@ pub async fn check_tasks< } } Err(e) => { - println!("{}", e); + log::error!("{}", e); } } } diff --git a/src/error.rs b/src/error.rs index 8f854ca..97b134c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -69,7 +69,7 @@ macro_rules! concat_pixiv_downloader_error { Err(e) => match $exp2 { Ok(_) => Err(e), Err(e2) => { - println!("{}", e); + log::error!("{}", e); Err(PixivDownloaderError::from(e2)) } }, @@ -88,7 +88,7 @@ macro_rules! concat_error { Err(e) => match $exp2 { Ok(_) => Err(e), Err(e2) => { - println!("{}", e); + log::error!("{}", e); Err(<$typ>::from(e2)) } }, diff --git a/src/fanbox/paginated_creator_posts.rs b/src/fanbox/paginated_creator_posts.rs index 70a7fb8..4ed8c21 100644 --- a/src/fanbox/paginated_creator_posts.rs +++ b/src/fanbox/paginated_creator_posts.rs @@ -64,7 +64,7 @@ impl PaginatedCreatorPosts { Some(d) => match FanboxItemList::new(&d["body"], Arc::clone(&self.client)) { Ok(d) => Some(d), Err(e) => { - println!("{} {}", gettext("Failed to parse posts's data:"), e); + log::error!("{} {}", gettext("Failed to parse posts's data:"), e); None } }, diff --git a/src/log_cfg.rs b/src/log_cfg.rs index 0028e65..a9bca3b 100644 --- a/src/log_cfg.rs +++ b/src/log_cfg.rs @@ -29,5 +29,5 @@ pub fn init_with_level(level: LevelFilter) { } pub fn init_default() { - init_with_level(LevelFilter::Warn); + init_with_level(LevelFilter::Info); } diff --git a/src/main.rs b/src/main.rs index 745b8b2..ff22979 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,7 +92,7 @@ impl Main { } ConfigCommand::Help => { let s = self.settings.as_ref().unwrap(); - println!("{}", gettext("All available settings:")); + log::error!("{}", gettext("All available settings:")); s.basic.print_help(); 0 } @@ -145,7 +145,7 @@ impl Main { let addr = get_helper().server(); match server::service::start_server(&addr).await { Ok(server) => { - println!("Listening on http://{}", addr); + log::info!("Listening on http://{}", addr); match server.await { Ok(_) => {} Err(e) => { diff --git a/src/opt/author_name_filter.rs b/src/opt/author_name_filter.rs index 5498e32..891f843 100644 --- a/src/opt/author_name_filter.rs +++ b/src/opt/author_name_filter.rs @@ -136,7 +136,7 @@ impl TryFrom<&JsonValue> for AuthorNameFilter { pub fn check_author_name_filters(v: &JsonValue) -> bool { let r = AuthorNameFilter::from_json(v); if r.is_err() { - println!( + log::error!( "{} {}", gettext("Failed parse author name filters:"), r.as_ref().unwrap_err() diff --git a/src/opt/proxy.rs b/src/opt/proxy.rs index e8a9420..0f3abf3 100644 --- a/src/opt/proxy.rs +++ b/src/opt/proxy.rs @@ -201,7 +201,7 @@ pub fn check_proxy(v: &JsonValue) -> bool { match ProxyChain::try_from(v) { Ok(_) => true, Err(e) => { - println!("{}", e); + log::error!("{}", e); false } } diff --git a/src/parser/description.rs b/src/parser/description.rs index 00d9f90..c74eb86 100644 --- a/src/parser/description.rs +++ b/src/parser/description.rs @@ -213,7 +213,6 @@ impl DescriptionParser { self.iter(node) } if self.nodes.len() != 0 { - println!(); return Err(format!( "{} {:?}", gettext("There are some nodes still in stack:"), @@ -230,7 +229,7 @@ pub fn parse_description + ?Sized>(desc: &S) -> Option { match p.parse(desc) { Ok(_) => Some(p.data), Err(e) => { - println!("{}", e); + log::error!("{}", e); None } } diff --git a/src/parser/metadata.rs b/src/parser/metadata.rs index 4e87bcb..4e8464e 100644 --- a/src/parser/metadata.rs +++ b/src/parser/metadata.rs @@ -53,7 +53,7 @@ impl MetaDataParser { } let r = json::parse(c.as_ref().unwrap()); if r.is_err() { - println!("{} {}", gettext("Failed to parse JSON:"), r.unwrap_err()); + log::error!("{} {}", gettext("Failed to parse JSON:"), r.unwrap_err()); return false; } self.value = Some(r.unwrap()); @@ -75,14 +75,14 @@ impl MetaDataParser { pub fn parse(&mut self, context: &str) -> bool { let r = Dom::parse(context); if r.is_err() { - println!("{} {}", gettext("Failed to parse HTML:"), r.unwrap_err()); + log::error!("{} {}", gettext("Failed to parse HTML:"), r.unwrap_err()); return false; } let dom = r.unwrap(); if dom.errors.len() > 0 { - println!("{}", gettext("Some errors occured during parsing:")); + log::error!("{}", gettext("Some errors occured during parsing:")); for i in dom.errors.iter() { - println!("{}", i); + log::error!("{}", i); } } for n in dom.children.iter() { diff --git a/src/server/service.rs b/src/server/service.rs index 8aa5fb6..ab303d6 100644 --- a/src/server/service.rs +++ b/src/server/service.rs @@ -34,13 +34,13 @@ impl Service> for PixivDownloaderSvc { } fn call(&mut self, req: Request) -> Self::Future { - println!("{} {}", req.method(), req.uri()); + log::info!(target: "server", "{} {}", req.method(), req.uri()); match self.routes.match_route(&req, &self.context) { Some(route) => Box::pin(async move { match route.response(req).await { Ok(data) => Ok(data), Err(e) => { - println!("{}", e); + log::error!(target: "server", "{}", e); Ok(Response::builder() .status(500) .body::>>(Box::pin(HyperBody::from( diff --git a/src/server/timer.rs b/src/server/timer.rs index 70a7c8a..fafc3d4 100644 --- a/src/server/timer.rs +++ b/src/server/timer.rs @@ -16,7 +16,7 @@ pub async fn start_timer(ctx: Arc) { for task in tasks.take_finished_tasks() { let re = task.await; if let Ok(Err(e)) = re { - println!("Timer task error: {}", e); + log::error!("Timer task error: {}", e); } } } diff --git a/src/settings.rs b/src/settings.rs index c89c504..cf9cc80 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -185,7 +185,7 @@ impl SettingDesStore { } s += t.as_str(); } - println!("{}", s); + log::error!("{}", s); } } @@ -265,7 +265,7 @@ impl SettingJar { match v.insert(val.name().as_str(), val.value()) { Ok(_) => {} Err(_) => { - println!("{}", gettext("Can not insert setting to JSON object.")); + log::error!("{}", gettext("Can not insert setting to JSON object.")); return None; } } @@ -340,7 +340,7 @@ impl SettingStore { } let re = File::open(path); if re.is_err() { - println!("{}", re.unwrap_err()); + log::error!("{}", re.unwrap_err()); return false; } let mut f = re.unwrap(); @@ -350,14 +350,14 @@ impl SettingStore { Ok(le) => { if le == 0 { if !fix_invalid { - println!("{}", gettext("Settings file is empty.")); + log::error!("{}", gettext("Settings file is empty.")); return false; } return true; } } Err(_) => { - println!("{}", gettext("Can not read from settings file.")); + log::error!("{}", gettext("Can not read from settings file.")); return false; } } @@ -366,7 +366,7 @@ impl SettingStore { Ok(_) => {} Err(_) => { if !fix_invalid { - println!("{}", gettext("Can not parse settings file.")); + log::error!("{}", gettext("Can not parse settings file.")); return false; } return true; @@ -375,7 +375,7 @@ impl SettingStore { let obj = re.unwrap(); if !obj.is_object() { if !fix_invalid { - println!("{}", gettext("Unknown settings file.")); + log::error!("{}", gettext("Unknown settings file.")); return false; } return true; @@ -387,7 +387,7 @@ impl SettingStore { if !re { if !fix_invalid { let s = gettext("\"\" is invalid, you can use \"pixiv_downloader config fix\" to remove all invalid value.").replace("", key); - println!("{}", s.as_str()); + log::error!("{}", s.as_str()); return false; } } else { @@ -405,7 +405,7 @@ impl SettingStore { pub fn save(&self, file_name: &str) -> bool { let obj = self.data.to_json(); if obj.is_none() { - println!("{}", gettext("Can not convert settings to JSON object.")); + log::error!("{}", gettext("Can not convert settings to JSON object.")); return false; } let obj = obj.unwrap(); @@ -415,25 +415,25 @@ impl SettingStore { match remove_file(path) { Ok(_) => {} Err(e) => { - println!("{} {}", gettext("Failed to remove file:"), e); + log::error!("{} {}", gettext("Failed to remove file:"), e); return false; } } } let r = File::create(path); if r.is_err() { - println!("{} {}", gettext("Failed to create file:"), r.unwrap_err()); + log::error!("{} {}", gettext("Failed to create file:"), r.unwrap_err()); return false; } let mut f = r.unwrap(); let r = f.write(s.as_bytes()); if r.is_err() { - println!("{} {}", gettext("Failed to write file:"), r.unwrap_err()); + log::error!("{} {}", gettext("Failed to write file:"), r.unwrap_err()); return false; } let r = f.flush(); if r.is_err() { - println!("{} {}", gettext("Failed to flush file:"), r.unwrap_err()); + log::error!("{} {}", gettext("Failed to flush file:"), r.unwrap_err()); return false; } true diff --git a/src/settings_list.rs b/src/settings_list.rs index 26b222d..03bbd37 100644 --- a/src/settings_list.rs +++ b/src/settings_list.rs @@ -82,7 +82,7 @@ fn check_cors_entries(obj: &JsonValue) -> bool { match parse_cors_entries(obj) { Ok(_) => true, Err(e) => { - println!("{}", e); + log::error!("{}", e); false } } diff --git a/src/utils.rs b/src/utils.rs index ba7b5b5..f919f47 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -49,14 +49,14 @@ pub fn ask_need_overwrite(path: &str) -> bool { pub fn get_file_name_from_url(url: U) -> Option { let u = url.into_url(); if u.is_err() { - println!("{} {}", gettext("Can not parse URL:"), u.unwrap_err()); + log::error!("{} {}", gettext("Can not parse URL:"), u.unwrap_err()); return None; } let u = u.unwrap(); let path = Path::new(u.path()); let re = path.file_name(); if re.is_none() { - println!( + log::error!( "{} {}", gettext("Failed to get file name from path:"), u.path() diff --git a/src/webclient.rs b/src/webclient.rs index c1200a4..64cc178 100644 --- a/src/webclient.rs +++ b/src/webclient.rs @@ -177,12 +177,12 @@ impl WebClient { self.get_cookies_as_mut().jar.get_mut().add(c); } None => { - println!("{}", gettext("Failed to parse Set-Cookie header.")); + log::warn!("{}", gettext("Failed to parse Set-Cookie header.")); } } } Err(e) => { - println!("{} {}", gettext("Failed to convert to string:"), e); + log::warn!("{} {}", gettext("Failed to convert to string:"), e); } } } @@ -237,7 +237,7 @@ impl WebClient { ) -> Option { let u = url.into_url(); if u.is_err() { - println!("{} \"{}\"", gettext("Can not parse URL:"), u.unwrap_err()); + log::error!("{} \"{}\"", gettext("Can not parse URL:"), u.unwrap_err()); return None; } let mut u = u.unwrap(); @@ -247,7 +247,7 @@ impl WebClient { } let obj = obj.unwrap(); if !obj.is_object() && !obj.is_array() { - println!( + log::error!( "{} \"{}\"", gettext("Parameters should be object or array:"), obj @@ -269,11 +269,11 @@ impl WebClient { } else { for v in obj.members() { if !v.is_object() { - println!("{} \"{}\"", gettext("Parameters should be array:"), v); + log::error!("{} \"{}\"", gettext("Parameters should be array:"), v); return None; } if v.len() < 2 { - println!("{} \"{}\"", gettext("Parameters need at least a value:"), v); + log::error!("{} \"{}\"", gettext("Parameters need at least a value:"), v); return None; } let okey = &v[0]; @@ -318,7 +318,7 @@ impl WebClient { let t = self.get_retry_interval().as_ref().unwrap()[(count - 1).try_into().unwrap()]; if !t.is_zero() { - println!( + log::info!( "{}", gettext("Retry after seconds.") .replace("", format!("{}", t.as_secs_f64()).as_str()) @@ -327,7 +327,7 @@ impl WebClient { tokio::time::sleep(t).await; } } - println!( + log::info!( "{}", gettext("Retry times now.") .replace("", format!("{}", count).as_str()) @@ -395,7 +395,7 @@ impl WebClient { let t = self.get_retry_interval().as_ref().unwrap()[(count - 1).try_into().unwrap()]; if !t.is_zero() { - println!( + log::info!( "{}", gettext("Retry after seconds.") .replace("", format!("{}", t.as_secs_f64()).as_str()) @@ -404,7 +404,7 @@ impl WebClient { tokio::time::sleep(t).await; } } - println!( + log::info!( "{}", gettext("Retry times now.") .replace("", format!("{}", count).as_str())