Add function to extract logs
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user