Improve log

This commit is contained in:
nyyu 2021-03-15 21:15:03 +01:00 committed by Gitea
parent 5b39644df0
commit 5117bbe659
2 changed files with 16 additions and 11 deletions

View file

@ -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);
}
}
}

View file

@ -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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
"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<dyn std::error::Error>> {
];
}
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();