src: Unclutter logs by switching some info messages to debug

This commit is contained in:
mirsal 2024-11-25 18:04:09 +00:00
parent e951fcdf83
commit 24d824f759
Signed by: mirsal
GPG Key ID: F78F9FE84AE5B610
3 changed files with 8 additions and 8 deletions

View File

@ -56,7 +56,7 @@ pub async fn fetch_and_parse_feed(uri: &str) -> Result<Feed, Box<dyn Error>> {
let http_client = reqwest::Client::builder().default_headers(headers).build()?; let http_client = reqwest::Client::builder().default_headers(headers).build()?;
let response = http_client.get(uri).send().await?.text().await?; let response = http_client.get(uri).send().await?.text().await?;
info!("Got response, parsing feed from {}", uri); debug!("Got response, parsing feed from {}", uri);
let feed = parser::parse(response.as_bytes())?; let feed = parser::parse(response.as_bytes())?;
let feed_title = match feed.title.clone() { let feed_title = match feed.title.clone() {
@ -64,7 +64,7 @@ pub async fn fetch_and_parse_feed(uri: &str) -> Result<Feed, Box<dyn Error>> {
None => String::from("Untitled") None => String::from("Untitled")
}; };
info!("Got feed with title \"{}\"", feed_title); debug!("Got feed with title \"{}\"", feed_title);
Ok(Feed { Ok(Feed {
uri: String::from(uri), uri: String::from(uri),

View File

@ -75,7 +75,7 @@ async fn main() -> anyhow::Result<()> {
}; };
let feed = if feed.is_none() { let feed = if feed.is_none() {
info!("Sleeping for {} seconds before refreshing this feed", feed_config.delay); debug!("Sleeping for {} seconds before refreshing this feed", feed_config.delay);
sleep(Duration::from_secs(feed_config.delay)).await; sleep(Duration::from_secs(feed_config.delay)).await;
continue; continue;
} else { } else {
@ -111,7 +111,7 @@ async fn main() -> anyhow::Result<()> {
debug!("State update complete"); debug!("State update complete");
} }
info!("Sleeping for {} seconds before refreshing this feed", feed_config.delay); debug!("Sleeping for {} seconds before refreshing this feed", feed_config.delay);
sleep(Duration::from_secs(feed_config.delay)).await; sleep(Duration::from_secs(feed_config.delay)).await;
} }
}) })

View File

@ -25,7 +25,7 @@ use std::{
use tokio::fs; use tokio::fs;
use chrono::{ DateTime, Utc }; use chrono::{ DateTime, Utc };
use tracing::{ info }; use tracing::{ info, debug };
use serde_yaml::mapping::Mapping as FeedReaderState; use serde_yaml::mapping::Mapping as FeedReaderState;
@ -55,17 +55,16 @@ impl FeedReaderStateDb {
) -> () { ) -> () {
{ {
info!("Updating feed reader state"); debug!("Updating feed reader state");
self.state.lock().unwrap().insert(uri.into(), dt.timestamp().into()); self.state.lock().unwrap().insert(uri.into(), dt.timestamp().into());
} }
info!("Persisting feed reader state");
self.persist().await.unwrap(); self.persist().await.unwrap();
} }
#[tracing::instrument(ret, level="debug")] #[tracing::instrument(ret, level="debug")]
pub fn get(&self, uri: &str) -> Option<DateTime<Utc>> { pub fn get(&self, uri: &str) -> Option<DateTime<Utc>> {
info!("Retrieving state for feed {}", uri); debug!("Retrieving state for feed {}", uri);
match self.state.lock().unwrap().get(uri) { match self.state.lock().unwrap().get(uri) {
Some(t) => DateTime::from_timestamp((*t).as_i64().unwrap(), 0), Some(t) => DateTime::from_timestamp((*t).as_i64().unwrap(), 0),
None => None None => None
@ -79,6 +78,7 @@ impl FeedReaderStateDb {
Ok(state) Ok(state)
} }
#[tracing::instrument(ret, level="debug")]
async fn persist(&self) -> Result<(), Box<dyn Error>> { async fn persist(&self) -> Result<(), Box<dyn Error>> {
let serialized_state = serde_yaml::to_string(&self.state)?; let serialized_state = serde_yaml::to_string(&self.state)?;
fs::write(self.filename.clone(), &serialized_state.as_bytes()).await?; fs::write(self.filename.clone(), &serialized_state.as_bytes()).await?;