From 7e64c17eb9ea40217818971e02ab65b6bb463334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= <~@hauleth.dev> Date: Fri, 24 Apr 2026 10:29:46 +0200 Subject: [PATCH] feat: improve logging - Reduce verbosity of cache cleanup logs by logging only if there were any entries removed. - Use structured logging with report callbacks for better observability. --- lib/aww.ex | 13 ++++++++++++- lib/aww/cache.ex | 11 ++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/aww.ex b/lib/aww.ex index f4c8d46..805a8cf 100644 --- a/lib/aww.ex +++ b/lib/aww.ex @@ -140,7 +140,13 @@ defmodule Aww do {:ok, ttl, {host, _} = result} -> if host in defederated do Logger.debug( - "Ignoring avatar from #{host}, because it was defederated" + %{ + kind: :ignore, + reason: :defederated, + host: host, + list: defederated + }, + report_cb: &__MODULE__.__report_cb__/1 ) {fallback, 60_000} @@ -234,4 +240,9 @@ defmodule Aww do _, _ -> :error end + + @doc false + def __report_cb__(%{kind: :ignore, reason: :defederated, host: host}) do + {"Ignoring avatar from ~p, because it was defederated", [host]} + end end diff --git a/lib/aww/cache.ex b/lib/aww/cache.ex index 042e8ae..98f2b4b 100644 --- a/lib/aww/cache.ex +++ b/lib/aww/cache.ex @@ -78,10 +78,19 @@ defmodule Aww.Cache do {{:_, :_, :"$1"}, [{:"=<", :"$1", timestamp}], [true]} ]) - Logger.debug("Deleted #{count} cached entries") + if count > 0 do + Logger.debug(%{cache: state.name, deleted: count}, + report_cb: &__MODULE__.__report_cb__/1 + ) + end Process.send_after(self(), :cleanup, state.cleanup) {:noreply, state} end + + @doc false + def __report_cb__(%{cache: name, deleted: count}) do + {"Deleted ~B entries from ~p cache", [count, name]} + end end -- 2.51.2