aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2024-08-16 07:12:33 -0400
committerNathan Perry <np@nathanperry.dev>2024-08-16 07:12:33 -0400
commitc5ce454319a7d54d3967c6ea7695543e943a37b2 (patch)
tree193a6907bc3a476f18774558ca52a3cb7618f912
parent5a2dc4070c1d14f22a7671c6f82ca2f4578369bd (diff)
tracing: use fields rather than interpolation
-rw-r--r--src/bin/batch_delmeme.rs4
-rw-r--r--src/bot.rs57
-rw-r--r--src/commands/game.rs11
-rw-r--r--src/commands/meme/create.rs4
-rw-r--r--src/commands/meme/delete.rs2
-rw-r--r--src/commands/meme/history.rs9
-rw-r--r--src/commands/meme/mod.rs2
-rw-r--r--src/commands/playback.rs4
-rw-r--r--src/commands/roll.rs4
-rw-r--r--src/commands/today/mod.rs2
-rw-r--r--src/config.rs4
-rw-r--r--src/util/mod.rs6
-rw-r--r--src/util/windows.rs4
13 files changed, 61 insertions, 52 deletions
diff --git a/src/bin/batch_delmeme.rs b/src/bin/batch_delmeme.rs
index 03aa6aa..e4f22e0 100644
--- a/src/bin/batch_delmeme.rs
+++ b/src/bin/batch_delmeme.rs
@@ -28,7 +28,7 @@ async fn create_demo_meme(conn: &mut AsyncPgConnection, owner: u64) -> anyhow::R
image_id: None,
};
let meme = meme.save(conn, owner).await?;
- tracing::debug!("created demo meme: {meme:#?}");
+ tracing::debug!(meme = ?meme, "created demo meme");
Ok(())
}
@@ -47,7 +47,7 @@ pub async fn main() -> anyhow::Result<()> {
}
let memes_deleted = db::del_memes_by_userid(&mut conn, opts.user_id, opts.deleter).await?;
- tracing::info!("deleted memes: {memes_deleted:?}");
+ tracing::info!(deleted_memes = ?memes_deleted);
Ok(())
}
diff --git a/src/bot.rs b/src/bot.rs
index ed6e118..6da1ac4 100644
--- a/src/bot.rs
+++ b/src/bot.rs
@@ -69,7 +69,7 @@ impl EventHandler for Handler {
let guild = r.guilds.iter().find(|g| g.id == CONFIG.discord.guild());
if guild.is_none() {
- tracing::info!("bot isn't in configured guild. join here: {:?}", OAUTH_URL.as_str());
+ tracing::info!(join_url = OAUTH_URL.as_str(), "bot isn't in configured guild");
return;
}
@@ -147,12 +147,12 @@ lazy_static! {
.and_then(|f| serde_json::from_reader::<_, Vec<u64>>(f).map_err(anyhow::Error::from));
if let Err(ref e) = restrict_ids {
- tracing::warn!("opening restrict file: {}", e);
+ tracing::warn!(error = %e, "opening restrict file");
}
let result = restrict_ids.unwrap_or_default().into_iter().collect::<FnvHashSet<_>>();
- tracing::info!("restricted ids: {result:?}");
+ tracing::info!(restricted_ids = ?result);
result
};
@@ -228,7 +228,7 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> {
if content.is_empty() {
if let Err(e) = util::reply(PoiseContext::Prefix(ctx), "what?").await {
- tracing::error!("responding to empty message: {e}");
+ tracing::error!(error = %e, "responding to empty message");
};
return;
@@ -247,14 +247,14 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> {
if let Err(e) =
commands::link_unrecognized(PoiseContext::Prefix(ctx), u).await
{
- tracing::error!("processing audio: {e}");
+ tracing::error!(error = %e, "processing audio");
"BANIC".to_string()
} else {
return;
}
},
Err(e) => {
- tracing::error!("processing unrecognized message: {e}");
+ tracing::error!(error = %e, "processing unrecognized message");
"BANIC".to_string()
},
}
@@ -266,7 +266,7 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> {
)
.await
{
- tracing::error!("producing meme for unrecognized: {e}");
+ tracing::error!(error = %e, "producing meme for unrecognized");
"BANIC".to_string()
} else {
return;
@@ -278,12 +278,12 @@ fn on_err(err: FrameworkError<PoiseData, anyhow::Error>) -> BoxFuture<()> {
tracing::error!("error encountered: {err:#?}");
if let Err(e) = msg.react(ctx, ReactionType::Unicode("❌".to_owned())).await {
- tracing::error!("reacting to failed message: {e}");
+ tracing::error!(error = %e, "reacting to failed message");
}
let cm = CreateMessage::default().content(text).tts(msg.tts);
if let Err(e) = msg.channel_id.send_message(ctx, cm).await {
- tracing::error!("sending error to chat: {e}");
+ tracing::error!(error = %e, "sending error to chat");
}
})
}
@@ -312,7 +312,7 @@ async fn framework() -> poise::Framework<PoiseData, anyhow::Error> {
commands: commands::commands(),
owners: HashSet::from_iter([CONFIG.discord.owner()]),
initialize_owners: false,
- skip_checks_for_owners: true,
+ skip_checks_for_owners: false,
..Default::default()
})
@@ -324,22 +324,30 @@ async fn framework() -> poise::Framework<PoiseData, anyhow::Error> {
fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> {
Box::pin(async move {
+ let span = tracing::debug_span!(
+ "check",
+ name = %ctx.command().name,
+ author = %ctx.author().name,
+ author_id = %ctx.author().id,
+ )
+ .entered();
+
if !ctx.guild_id().map_or(false, |x| x == CONFIG.discord.guild()) {
- tracing::info!(
- "rejecting command '{}' from user '{}': wrong guild",
- ctx.command().name,
- ctx.author().name
- );
+ tracing::info!("rejecting command, wrong guild");
+
return Ok(false);
}
if ctx.author().id == CONFIG.discord.owner() {
+ tracing::info!("author is owner");
+
return Ok(true);
}
let restricted_prefix = RESTRICTED_PREFIXES.iter().any(|&prefix| ctx.prefix() == prefix);
if !restricted_prefix {
+ tracing::debug!("command isn't restricted");
return Ok(true);
}
@@ -349,6 +357,7 @@ fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> {
let restrictions_flipped = chrono::Local::now().weekday() == PERMITTED_WEEKDAY;
if user_is_restricted == restrictions_flipped {
+ tracing::debug!("authorized for restricted command");
return Ok(true);
}
@@ -359,12 +368,12 @@ fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> {
};
tracing::info!(
- "rejecting command '{}' from user '{}': {}",
- ctx.command().name,
- ctx.author().name,
- reason
+ %reason,
+ "reject restricted command",
);
+ drop(span);
+
util::reply(ctx, "no").await?;
Ok(false)
@@ -373,10 +382,10 @@ fn check(ctx: PoiseContext) -> BoxFuture<anyhow::Result<bool>> {
fn before_handle<'fut>(ctx: PoiseContext<'fut>) -> Pin<Box<dyn Future<Output = ()> + Send + 'fut>> {
tracing::debug!(
- "got command '{}' from user '{}' ({})",
- ctx.command().name,
- ctx.author().name,
- ctx.author().id
+ name = %ctx.command().name,
+ author = %ctx.author().name,
+ author_id = %ctx.author().id,
+ "got command",
);
Box::pin(async {})
@@ -384,7 +393,7 @@ fn before_handle<'fut>(ctx: PoiseContext<'fut>) -> Pin<Box<dyn Future<Output = (
fn after_handle(ctx: PoiseContext) -> BoxFuture<()> {
Box::pin(async move {
- tracing::trace!("command '{}' completed successfully", ctx.command().name);
+ tracing::trace!(name = %ctx.command().name, "command completed successfully");
})
}
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::<FnvHashMap<_, _>>();
tracing::info!(
- "loaded user info for {} users ({:#?})",
- result.len(),
- result.keys().collect::<Vec<_>>()
+ users = ?result.keys().collect::<Vec<_>>(),
+ "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<String>) -> 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<String>) -> anyhow::
let games_owned =
games_owned.response.games.into_iter().map(|ge| ge.app_id).collect::<FnvHashSet<_>>();
- 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::<DieselError>() {
- 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<usize>) -> 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<usize>) -> 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<usize>) -> anyhow::Result<
Err(e) => {
if let Some(variant) = e.downcast_ref::<DieselError>() {
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::<u32>() % 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<Songbird>, 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<U: Send + Sync>(
) -> 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<String>) -> anyh
let options: Vec<TodayArgs> = 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());
diff --git a/src/config.rs b/src/config.rs
index 046a2be..a5ac928 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -18,13 +18,13 @@ lazy_static! {
};
pub static ref FFMPEG_COMMAND: String = {
let result = CONFIG.ffmpeg.clone().unwrap_or("ffmpeg".to_owned());
- tracing::debug!("got ffmpeg: {result}");
+ tracing::debug!(ffmpeg = %result, "got ffmpeg");
result
};
pub static ref YTDL_COMMAND: String = {
let result = CONFIG.ytdl.clone().unwrap_or("yt-dlp".to_owned());
- tracing::debug!("got ytdl: {result}");
+ tracing::debug!(ytdl = %result, "got ytdl");
result
};
diff --git a/src/util/mod.rs b/src/util/mod.rs
index c5bed98..9355e48 100644
--- a/src/util/mod.rs
+++ b/src/util/mod.rs
@@ -161,7 +161,7 @@ pub async fn send_result(
tts: bool,
) -> anyhow::Result<MessageId> {
let text = text.as_ref();
- tracing::debug!("sending message {:?} to channel {:?} (tts: {})", text, channel, tts);
+ tracing::debug!(text, %channel, tts, "sending message");
let result = channel.send_message(ctx, CreateMessage::default().content(text).tts(tts)).await?;
Ok(result.id)
@@ -203,12 +203,12 @@ pub async fn ytdl_url(uri: &str) -> anyhow::Result<String> {
uri,
];
- tracing::debug!("downloading info for uri: {uri}");
+ tracing::debug!(uri, "downloading info");
let mut command = Command::new(&*crate::config::YTDL_COMMAND);
command.args(args).stdin(Stdio::null());
- tracing::debug!("running command: {command:?}");
+ tracing::debug!(?command, "running command");
let out = command.output().await?;
diff --git a/src/util/windows.rs b/src/util/windows.rs
index 8856aed..7003490 100644
--- a/src/util/windows.rs
+++ b/src/util/windows.rs
@@ -114,13 +114,13 @@ pub unsafe fn get_psql_service(
},
other => {
- tracing::warn!("unable to identify postgres service: {other} potential matches found");
+ tracing::warn!(n_candidates = other, "unable to identify postgres service");
return Ok(None);
},
}
let svc = psql_services.remove(0);
- tracing::debug!("identified postgres service: {}", svc.name);
+ tracing::debug!(name = %svc.name, "identified postgres service");
Ok(Some(svc))
}