Skip to content

Plug/Phoenix logs crash #169

@mxgrn

Description

@mxgrn

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions