Skip to content

Commit

Permalink
Improve structured-ness of logging
Browse files Browse the repository at this point in the history
  • Loading branch information
elkowar committed Oct 26, 2023
1 parent ad97cfe commit 4484537
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions crates/robbb/src/attachment_logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub async fn store_attachments(
/// Store a single attachment in the given directory path.
async fn store_single_attachment(dir_path: impl AsRef<Path>, attachment: Attachment) -> Result<()> {
let file_path = dir_path.as_ref().join(attachment.filename);
tracing::debug!("Storing file {}", &file_path.display());
tracing::debug!(file_path = %file_path.display(), "Storing file {}", &file_path.display());

let resp = reqwest::get(&attachment.url).await.context("Failed to load attachment")?;
let mut body = resp
Expand Down Expand Up @@ -104,10 +104,11 @@ pub async fn cleanup(config: &Config) -> Result<()> {
files.sort_by_key(|(_, meta)| meta.modified().expect("Unsupported platform"));
}

tracing::info!("{} bytes currently occupied by attachment logging", total_size_bytes);
tracing::info!(attachment_logs.total_size_bytes = %total_size_bytes, "Performing attachment cleanup");

while total_size_bytes > config.attachment_cache_max_size && !files.is_empty() {
let (file, meta) = files.remove(0);
tracing::trace!(file_name = %file.path().display(), size = meta.size(), "Deleting file");
tokio::fs::remove_file(file.path())
.instrument(tracing::info_span!("Deleting file", file_name = %file.path().display(), size = meta.size()))
.await?;
Expand Down
1 change: 1 addition & 0 deletions crates/robbb/src/events/guild_member_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub async fn dehoist_member(ctx: client::Context, member: Member) -> Result<()>
} else {
cleaned_name.to_string()
};
tracing::info!(user.old_name = %display_name, user.cleaned_name = %cleaned_name, "Dehoisting user");
member
.edit(&ctx, |edit| edit.nickname(&cleaned_name))
.instrument(tracing::info_span!("dehoist-edit-nickname", member.tag = %member.user.tag(), dehoist.old_nick = %display_name, dehoist.new_nick = %cleaned_name))
Expand Down
2 changes: 1 addition & 1 deletion crates/robbb/src/events/ready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub async fn ready(ctx: client::Context, _data_about_bot: Ready) -> Result<()> {
let config = ctx.get_config().await;

let bot_version = util::bot_version();
tracing::info!("Robbb is ready! Running version {}", &bot_version);
tracing::info!(robbb_version = %bot_version, "Robbb is ready! Running version {}", &bot_version);

let _ = config
.channel_mod_bot_stuff
Expand Down

0 comments on commit 4484537

Please sign in to comment.