This feels like there's something I missed in plain sight, but I tried to use logger_json to send logs via fluentd to SigNoz, and it's crashing when Plug/Phoenix logs get send to the lib as iolist, not binary.
I had to implement the following custom formatter in my Phoenix app for a work-around:
defmodule MyApp.JSONFormatter do
@moduledoc """
Wraps LoggerJSON.Formatters.Basic to convert iolist messages to binaries,
preventing formatter crashes from Plug/Phoenix request logging.
"""
def format(%{msg: {:string, msg}} = event, config) when is_list(msg) do
LoggerJSON.Formatters.Basic.format(%{event | msg: {:string, IO.iodata_to_binary(msg)}}, config)
end
def format(event, config) do
LoggerJSON.Formatters.Basic.format(event, config)
end
end
Does this ring a bell? If this this isn't enough or too vague, I could try to come up with a failing test for logger_json.
This feels like there's something I missed in plain sight, but I tried to use logger_json to send logs via fluentd to SigNoz, and it's crashing when Plug/Phoenix logs get send to the lib as iolist, not binary.
I had to implement the following custom formatter in my Phoenix app for a work-around:
Does this ring a bell? If this this isn't enough or too vague, I could try to come up with a failing test for logger_json.