I think I figured it out.
What I did was add a :other field to my metadata array, then i adde a case for my custom log formatter to handle that field.
So my config became like this:
config :logger, :console,
level: :debug,
metadata: [:other],
format: {Log.Formatter, :format}
And my formatter like this:
defmodule Log.Formatter do
@moduledoc false
alias IO.ANSI
@color_reset ANSI.reset()
@highlight ANSI.light_magenta()
def format(:debug, message, timestamp, metadata),
do: format(:debug, message, timestamp, metadata, ANSI.cyan())
def format(:info, message, timestamp, metadata),
do: format(:info, message, timestamp, metadata, ANSI.green())
def format(:notice, message, timestamp, metadata),
do: format(:notice, message, timestamp, metadata, ANSI.light_yellow())
def format(:warn, message, timestamp, metadata),
do: format(:warn, message, timestamp, metadata, ANSI.yellow())
def format(:warning, message, timestamp, metadata),
do: format(:warn, message, timestamp, metadata, ANSI.yellow())
def format(:error, message, timestamp, metadata),
do: format(:error, message, timestamp, metadata, ANSI.red())
def format(:critical, message, timestamp, metadata),
do: format(:critical, message, timestamp, metadata, ANSI.yellow_background())
def format(:alert, message, timestamp, metadata),
do: format(:alert, message, timestamp, metadata, ANSI.light_red_background())
def format(:emergency, message, timestamp, metadata),
do: format(:emergency, message, timestamp, metadata, ANSI.red_background())
defp format(level, message, timestamp, metadata, color) do
date_time = format_date_time(timestamp)
metadata = format_metadata(metadata, color)
"\n#{color}#{date_time} [#{level}] #{metadata}\n↳ #{message}#{@color_reset}\n"
rescue
_ -> "Could not format message: #{inspect({level, message, timestamp, metadata})}"
end
# This is the function I added
defp format_metadata([{:other, value} | rest], color) do
"#{@highlight}#{inspect(value)}#{color} " <> format_metadata(rest, color)
end
defp format_metadata([{_key, value} | rest], color) do
"#{inspect(value)} " <> format_metadata(rest, color)
end
defp format_metadata([], _), do: ""
defp format_date_time({date, time}) do
alias Logger.Formatter
"#{Formatter.format_date(date)} #{Formatter.format_time(time)}"
end
end
That way, I can send any data to it using the other metadata,
For example, Logger.error("blibs", other: %{blibs: 2}) will be logged as:
2025-07-14 19:23:44.530 [error] #PID<0.770.0> %{blibs: 2}
↳ blibs