Migrate to structured logging

This commit is contained in:
micialware committed 2026-08-23 22:48:00 +03:00
1 parent 0367d5001b
commit 0baf6cadf7
13 files changed
+202 -30

No files matched your search

+3 -2
View File
@@ -1,6 +1,7 @@
use crate::lang::{CardStatistics, DeckSettings};
use rusqlite::{Connection, params};
use std::time::Instant;
use log::info;
pub fn load_stats_of_deck(set: &DeckSettings, connection: &Connection) -> Vec<CardStatistics> {
let mut stmt = connection
@@ -58,7 +59,7 @@ pub fn add_stat_list(stats: &mut [CardStatistics], connection: &mut Connection)
stats[index].id = id.into();
}
println!("Added {} cards for {:?}", stats.len(), time.elapsed());
info!("Added {} cards for {:?}", stats.len(), time.elapsed());
}
pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) {
@@ -70,7 +71,7 @@ pub fn update_stat_score(stat: &CardStatistics, connection: &Connection) {
(&stat.score, &stat.last_open.timestamp(), &stat.id),
)
.unwrap();
println!("Updated stat: {}", time.elapsed().as_millis());
info!("Updated stat: {}", time.elapsed().as_millis());
}
pub fn delete_stats(stat: &[CardStatistics], connection: &Connection) {
+4 -3
View File
@@ -1,5 +1,6 @@
use crate::notification::NotificationData;
use hashbrown::HashMap;
use log::info;
use rusqlite::Connection;
use serde_json::Value;
@@ -53,7 +54,7 @@ pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationDa
.map(|x| x.as_str().unwrap().to_string())
.collect();
let id = collection.get("id");
if id.is_none() {
if id.is_none() {
return Err(NotificationData::IncorrectAnkiFile);
}
let id = id.unwrap().as_u64().unwrap();
@@ -62,7 +63,7 @@ pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationDa
return Err(NotificationData::IncorrectAnkiFile);
}
let name = name.unwrap().as_str().unwrap().to_string();
let mut group = ImportGroup {
id,
name,
@@ -74,7 +75,7 @@ pub fn load_groups(connection: &Connection) -> Result<ImportData, NotificationDa
if let Some((_, count)) = counts.iter().find(|(id, _)| *id == group.id as i64) {
group.length = *count as u64
}
println!("{:?}", group);
info!("{:?}", group);
total_data.0.push(group);
}
}
+4 -3
View File
@@ -1,5 +1,6 @@
use crate::dictionary::app_data_dir;
use std::io;
use log::info;
use reqwest::Error;
use tokio::fs::{File, OpenOptions};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
@@ -72,7 +73,7 @@ pub fn decompress(data: Vec<u8>) -> Vec<u8> {
let mut decompressed = Vec::new();
let res = io::copy(&mut decoder, &mut decompressed);
if let Err(e) = res {
println!("{}", e);
info!("{}", e);
}
decompressed
}
@@ -89,7 +90,7 @@ pub async fn first_sync() -> Result<String, NotificationData> {
.text()
.await
.map_err(|_| WebApiUnavailable)?;
println!("id: {}", id);
info!("id: {}", id);
Ok(id)
}
@@ -97,7 +98,7 @@ pub async fn get_web_version(key: &str) -> Result<u32, NotificationData> {
let id_url = format!("{API_URL}{key}/version");
let client = reqwest::Client::new();
let version = client.get(&id_url).send().await.map_err(|_| WebApiUnavailable)?.text().await.map_err(|_| WebApiUnavailable)?;
println!("version: {}", version);
info!("version: {}", version);
Ok(version.parse::<u32>().unwrap_or_default())
}