From c5ce454319a7d54d3967c6ea7695543e943a37b2 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Fri, 16 Aug 2024 07:12:33 -0400 Subject: tracing: use fields rather than interpolation --- src/commands/game.rs | 11 +++++------ src/commands/meme/create.rs | 4 ++-- src/commands/meme/delete.rs | 2 +- src/commands/meme/history.rs | 9 +++++---- src/commands/meme/mod.rs | 2 +- src/commands/playback.rs | 4 ++-- src/commands/roll.rs | 4 ++-- src/commands/today/mod.rs | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) (limited to 'src/commands') diff --git a/src/commands/game.rs b/src/commands/game.rs index 258feaf..5c51da6 100644 --- a/src/commands/game.rs +++ b/src/commands/game.rs @@ -83,9 +83,8 @@ lazy_static! { .collect::>(); tracing::info!( - "loaded user info for {} users ({:#?})", - result.len(), - result.keys().collect::>() + users = ?result.keys().collect::>(), + "loaded user info" ); result @@ -272,7 +271,7 @@ async fn _game( let res = DISCORD_MAP.get(&uid).map(|s| s.to_lowercase()); if res.is_none() { - tracing::info!("user {uid} is not recognized"); + tracing::info!(%uid, "user is not recognized"); } res @@ -454,7 +453,7 @@ pub async fn updategaem(ctx: PoiseContext<'_>, user: Option) -> anyhow:: }, }; - tracing::debug!("parsed userid {:?}", user); + tracing::debug!(%user, "parsed userid"); let username = match DISCORD_MAP.get(&user) { Some(s) => s, @@ -551,7 +550,7 @@ pub async fn updategaem(ctx: PoiseContext<'_>, user: Option) -> anyhow:: let games_owned = games_owned.response.games.into_iter().map(|ge| ge.app_id).collect::>(); - tracing::debug!("user owns {} steam games", games_owned.len()); + tracing::debug!(n_games = games_owned.len(), %username, %steam_id, "got owned games"); let found_games = missing_appids .filter_map(|(ai, x)| { diff --git a/src/commands/meme/create.rs b/src/commands/meme/create.rs index a4e9656..c6ed9c6 100644 --- a/src/commands/meme/create.rs +++ b/src/commands/meme/create.rs @@ -109,7 +109,7 @@ pub async fn addaudiomeme( util::react(ctx, '🔃').await?; let youtube_url = util::ytdl_url(audio_link.as_str()).await?; - tracing::debug!("got download url: {youtube_url}"); + tracing::debug!(url_string = &youtube_url, "got download url"); let duration_opts = if let Some(e) = end { vec![ @@ -162,7 +162,7 @@ pub async fn addaudiomeme( let mut audio_data = Vec::new(); let bytes = audio_reader.read_to_end(&mut audio_data).await?; - tracing::debug!("downloaded audio ({} bytes)", audio_data.len()); + tracing::debug!(len_bytes = audio_data.len(), "downloaded audio"); if bytes == 0 { tracing::debug!("read 0 bytes from audio reader"); diff --git a/src/commands/meme/delete.rs b/src/commands/meme/delete.rs index 560da28..8adaa6c 100644 --- a/src/commands/meme/delete.rs +++ b/src/commands/meme/delete.rs @@ -26,7 +26,7 @@ pub async fn delmeme(ctx: PoiseContext<'_>, title: String) -> anyhow::Result<()> }, Err(e) => { if let Some(NotFound) = e.downcast_ref::() { - tracing::info!("attempted to delete nonexistent meme: '{}'", title); + tracing::info!(title, "attempted to delete nonexistent meme"); util::react(ctx, ReactionType::Unicode("❓".to_owned())).await?; util::reply(ctx, "nice try").await?; diff --git a/src/commands/meme/history.rs b/src/commands/meme/history.rs index e3d0de3..d6ccdcf 100644 --- a/src/commands/meme/history.rs +++ b/src/commands/meme/history.rs @@ -107,9 +107,10 @@ pub async fn history(ctx: PoiseContext<'_>, n: Option) -> anyhow::Result< if n > CONFIG.max_hist { tracing::debug!( - "user requested more than MAX_HIST ({}) items from history", - CONFIG.max_hist + MAX_HIST = CONFIG.max_hist, + "user requested more than MAX_HIST items from history", ); + util::reply(ctx, "YER PUSHIN ME OVER THE FUCKIN LINE").await?; } @@ -127,7 +128,7 @@ pub async fn history(ctx: PoiseContext<'_>, n: Option) -> anyhow::Result< return Ok(()); } - tracing::info!("reporting meme history (len {})", n); + tracing::info!(len = n, "reporting meme history"); let resp = serenity::futures::stream::iter(records.into_iter().enumerate().rev()) .then(|(i, rec)| async move { @@ -181,7 +182,7 @@ pub async fn history(ctx: PoiseContext<'_>, n: Option) -> anyhow::Result< Err(e) => { if let Some(variant) = e.downcast_ref::() { if *variant != NotFound { - tracing::error!("error encountered loading meme history: {}", e); + tracing::error!(error = %e, "error encountered loading meme history"); } } diff --git a/src/commands/meme/mod.rs b/src/commands/meme/mod.rs index 4819c1d..7bc8b2e 100644 --- a/src/commands/meme/mod.rs +++ b/src/commands/meme/mod.rs @@ -70,7 +70,7 @@ async fn send_meme( let should_tts = t.content.as_ref().map(|t| !t.is_empty()).unwrap_or(false) && random::() % 25 == 0; - tracing::debug!("sending meme (tts: {}): {:?}", should_tts, t); + tracing::debug!(should_tts, meme = ?t, "sending meme"); let image = t.image(conn).await; let audio = t.audio(conn).await; diff --git a/src/commands/playback.rs b/src/commands/playback.rs index ad24eb3..50ac8bb 100644 --- a/src/commands/playback.rs +++ b/src/commands/playback.rs @@ -33,9 +33,9 @@ pub async fn songbird(ctx: PoiseContext<'_>) -> anyhow::Result<(Arc, A pub async fn _play(ctx: PoiseContext<'_>, url: &url::Url) -> anyhow::Result<()> { use url::Host; - tracing::debug!("playing '{}'", url); + tracing::debug!(%url, "playing"); if !url.scheme().starts_with("http") { - tracing::warn!("got bad url argument to play: {}", url); + tracing::warn!(%url, "got bad url argument"); util::reply(ctx, "bAD LiNk").await?; return Ok(()); diff --git a/src/commands/roll.rs b/src/commands/roll.rs index 16fe15f..5dfdb77 100644 --- a/src/commands/roll.rs +++ b/src/commands/roll.rs @@ -9,11 +9,11 @@ pub async fn roll( ) -> anyhow::Result<()> { match thulani_calc::Calc::eval(&rest) { Ok(result) => { - tracing::debug!("got calc result '{}'", result); + tracing::debug!(result, expr = %rest, "got calc result"); util::reply(ctx, result.to_string()).await?; }, Err(e) => { - tracing::error!("error encountered reading calc '{}': {}", rest, e); + tracing::error!(error = %e, expr = %rest, "error encountered reading calc"); util::reply(ctx, "I COULDN'T READ THAT YOU FUCK").await?; }, } diff --git a/src/commands/today/mod.rs b/src/commands/today/mod.rs index 0b9b857..35059e5 100644 --- a/src/commands/today/mod.rs +++ b/src/commands/today/mod.rs @@ -91,7 +91,7 @@ pub async fn today(ctx: PoiseContext<'_>, #[rest] _rest: Option) -> anyh let options: Vec = ALL.iter().flat_map(|f| f(today)).collect(); - tracing::debug!("{} options for {}", options.len(), today); + tracing::debug!(option_count = options.len(), %today); let play_args = options.choose(&mut thread_rng()); -- cgit v1.3.1