From 5a2dc4070c1d14f22a7671c6f82ca2f4578369bd Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Fri, 16 Aug 2024 06:40:25 -0400 Subject: rework logging to use tracing via grate --- src/commands/meme/history.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/commands/meme/history.rs') diff --git a/src/commands/meme/history.rs b/src/commands/meme/history.rs index 68416e5..e3d0de3 100644 --- a/src/commands/meme/history.rs +++ b/src/commands/meme/history.rs @@ -3,13 +3,9 @@ use diesel::{ result::Error as DieselError, NotFound, }; +use grate::tracing; use itertools::Itertools; use lazy_static::lazy_static; -use log::{ - debug, - error, - info, -}; use serenity::{ futures::{ StreamExt, @@ -58,7 +54,7 @@ pub async fn wat(ctx: PoiseContext<'_>) -> anyhow::Result<()> { Ok(x) => x, Err(e) => { if let Some(NotFound) = e.downcast_ref::() { - info!("found no memes in history"); + tracing::info!("found no memes in history"); util::reply(ctx, "no one has ever memed before").await?; return Ok(()); @@ -89,7 +85,7 @@ pub async fn wat(ctx: PoiseContext<'_>) -> anyhow::Result<()> { }, Err(e) => { if let Some(NotFound) = e.downcast_ref::() { - info!("last meme not found in database"); + tracing::info!("last meme not found in database"); util::reply(ctx, "heuueueeeeh?").await?; return Ok(()); @@ -110,7 +106,10 @@ pub async fn history(ctx: PoiseContext<'_>, n: Option) -> anyhow::Result< let n = n.unwrap_or(CONFIG.default_hist); if n > CONFIG.max_hist { - debug!("user requested more than MAX_HIST ({}) items from history", CONFIG.max_hist); + tracing::debug!( + "user requested more than MAX_HIST ({}) items from history", + CONFIG.max_hist + ); util::reply(ctx, "YER PUSHIN ME OVER THE FUCKIN LINE").await?; } @@ -122,13 +121,13 @@ pub async fn history(ctx: PoiseContext<'_>, n: Option) -> anyhow::Result< }; if records.is_empty() { - info!("no memes in history"); + tracing::info!("no memes in history"); util::reply(ctx, "i don't remember anything :(").await?; return Ok(()); } - info!("reporting meme history (len {})", n); + tracing::info!("reporting meme history (len {})", n); let resp = serenity::futures::stream::iter(records.into_iter().enumerate().rev()) .then(|(i, rec)| async move { @@ -182,7 +181,7 @@ pub async fn history(ctx: PoiseContext<'_>, n: Option) -> anyhow::Result< Err(e) => { if let Some(variant) = e.downcast_ref::() { if *variant != NotFound { - error!("error encountered loading meme history: {}", e); + tracing::error!("error encountered loading meme history: {}", e); } } @@ -213,7 +212,7 @@ pub async fn stats(ctx: PoiseContext<'_>) -> anyhow::Result<()> { let mut conn = connection().await?; let stats = db::stats(&mut conn).await?; - debug!("reporting stats"); + tracing::debug!("reporting stats"); let rand_user: User = UserId::new(stats.most_random_meme_user).to_user(&ctx).await?; let direct_user: User = UserId::new(stats.most_directly_named_meme_user).to_user(&ctx).await?; @@ -408,7 +407,7 @@ pub async fn query(ctx: PoiseContext<'_>, rest: util::RestVec) -> anyhow::Result .join("\n"); if result.is_empty() { - info!("no memes matched query"); + tracing::info!("no memes matched query"); util::reply(ctx, "no match").await?; return Ok(()); -- cgit v1.3.1