Add function to extract logs

This commit is contained in:
2024-10-01 22:27:34 +02:00
parent 63bdeed952
commit 75753051f9
5 changed files with 55 additions and 2 deletions

View File

@ -39,3 +39,20 @@ pub fn save_log(
Ok(())
}
/// Make a logs extraction
pub fn get_logs(day: u64) -> anyhow::Result<Vec<LogEntry>> {
let file = AppConfig::get().log_of_day(day);
if !file.exists() {
return Ok(Vec::new());
}
let content = std::fs::read_to_string(file)?
.split('\n')
.filter(|l| !l.is_empty())
.map(serde_json::from_str)
.collect::<Result<Vec<_>, _>>()?;
Ok(content)
}