From 5117bbe6593042e6cf8e85feb8a37db9599948c3 Mon Sep 17 00:00:00 2001 From: nyyu Date: Mon, 15 Mar 2021 21:15:03 +0100 Subject: [PATCH] Improve log --- src/data_source.rs | 6 +++--- src/main.rs | 21 +++++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/data_source.rs b/src/data_source.rs index 924c936..f9fc719 100644 --- a/src/data_source.rs +++ b/src/data_source.rs @@ -62,7 +62,7 @@ pub trait DataSource { path: &PathBuf, client: &ureq::Agent, ) { - info!("Retrieving data for {} at {}", champ.name, pos); + info!("{}: Retrieving data for {} at {}", self.get_alias(), champ.name, pos); let data = self.get_champ_data_with_win_pourcentage(champ, pos, client); match data { @@ -77,7 +77,7 @@ pub trait DataSource { blocks: data.0, }; - info!("Writing item set for {} at {}", champ.name, pos); + info!("{}: Writing item set for {} at {}", self.get_alias(), champ.name, pos); fs::write( path.join(format!("{}_{}_{}.json", self.get_alias(), champ.id, pos)), serde_json::to_string_pretty(&item_set).unwrap(), @@ -85,7 +85,7 @@ pub trait DataSource { .unwrap(); } None => { - error!("Can't get data for {} at {}", champ.id, pos); + error!("{}: Can't get data for {} at {}", self.get_alias(), champ.id, pos); } } } diff --git a/src/main.rs b/src/main.rs index ddfb5d9..f9b164c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ use std::io::Error; #[cfg(target_os = "windows")] use std::io::ErrorKind; use std::path::PathBuf; +use std::time::Instant; use std::{fs, thread, time}; use time::Duration; #[cfg(target_os = "windows")] @@ -44,7 +45,6 @@ pub struct ChampInfo { key: String, } -const USER_AGENT_KEY: &str = "User-Agent"; const USER_AGENT_VALUE: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0"; const DEFAULT_LOL_CHAMPS_DIR: &str = ".\\champs"; @@ -64,11 +64,13 @@ fn main() -> Result<(), Box> { for s in &args { if s.eq_ignore_ascii_case("-v") || s.eq_ignore_ascii_case("--verbose") { level = LevelFilter::Debug; + break; } } SimpleLogger::new() .with_level(level) .with_module_level("ureq", LevelFilter::Error) + .with_module_level("rustls", LevelFilter::Error) .init()?; info!("CGG Item Sets"); @@ -78,11 +80,11 @@ fn main() -> Result<(), Box> { Err(_e) => PathBuf::from(DEFAULT_LOL_CHAMPS_DIR), }; static ref CLIENT: ureq::Agent = ureq::AgentBuilder::new() + .user_agent(USER_AGENT_VALUE) .timeout(Duration::from_secs(10)) .build(); static ref REALM: Realm = CLIENT .get("https://ddragon.leagueoflegends.com/realms/euw.json") - .set(USER_AGENT_KEY, USER_AGENT_VALUE) .call() .unwrap() .into_json() @@ -92,7 +94,6 @@ fn main() -> Result<(), Box> { "https://ddragon.leagueoflegends.com/cdn/{}/data/en_US/champion.json", REALM.v )) - .set(USER_AGENT_KEY, USER_AGENT_VALUE) .call() .unwrap() .into_json() @@ -104,16 +105,20 @@ fn main() -> Result<(), Box> { ]; } - info!( - "LoL Champs Folder: {}", LOL_CHAMPS_DIR.to_str().unwrap() - ); + info!("LoL Champs Folder: {}", LOL_CHAMPS_DIR.to_str().unwrap()); info!("LoL version: {}", REALM.v); info!("LoL numbers of champs: {}", CHAMPION.data.len()); let mut threads = vec![]; for data_source in DATA_SOURCES.iter() { threads.push(thread::spawn(move || { - execute_data_source(&data_source, &CLIENT, &CHAMPION, &LOL_CHAMPS_DIR) + let init = Instant::now(); + execute_data_source(&data_source, &CLIENT, &CHAMPION, &LOL_CHAMPS_DIR); + info!( + "{}: done in {} ms", + data_source.get_alias(), + init.elapsed().as_millis() + ); })); } for child in threads { @@ -157,7 +162,7 @@ fn execute_data_source( if let Some(champ) = champion.data.get(&champ_id) { if positions.is_empty() { - error!("{} missing positions", &champ_id); + error!("{}: {} empty positions", data_source.get_alias(), &champ_id); } else { let path = lol_champs_dir.join(&champ_id).join("Recommended"); fs::create_dir_all(&path).unwrap();