Why is Logger's :file metadata field a charlist?

I noticed that the file field is coming out as an array of numbers instead of a string in our JSON logs (also applies to the default formatter btw).

CleanShot 2024-10-10 at 14.40.42

My first instinct was to fix this in the formatter, which is logstash_logger_formatter in our case. After digging a little bit deeper I saw that Logger specifically converts the file to a charlist in compile_time_application_and_file/1.

  defp compile_time_application_and_file(%{file: file}) do
    if app = Application.get_env(:logger, :compile_time_application) do
      {[application: app], file |> Path.relative_to_cwd() |> String.to_charlist()}
    else
      {[], String.to_charlist(file)}
    end
  end

Can anyone help me understand why it must be a charlist?

Because that’s the type expected im metadata: logger — kernel v10.0.1

Thanks for clearing that up!

And also I take back what I said about the default format, file is correctly printed there.
I’ll go ahead and try to fix this in the logstash_logger_formatter package.