Add support for ports in Logger metadata (#12332)

Resolves #12328
This commit is contained in:
bbhoss
2023-01-12 00:26:56 +01:00
committed by GitHub
parent dea8b432ea
commit cb2fd9db38
2 changed files with 9 additions and 0 deletions
+5
View File
@@ -266,6 +266,11 @@ defmodule Logger.Formatter do
rest
end
defp metadata(_, port) when is_port(port) do
~c"#Port" ++ rest = :erlang.port_to_list(port)
rest
end
defp metadata(:file, file) when is_list(file), do: file
defp metadata(:domain, [head | tail]) when is_atom(head) do
@@ -68,6 +68,10 @@ defmodule Logger.FormatterTest do
assert IO.chardata_to_string(format(compiled, :error, nil, nil, meta: :data, ref: ref)) ==
"meta=data ref=<0.0.0.80> "
port = :erlang.list_to_port(~c"#Port<0.1234>")
format = format(compiled, :error, nil, nil, meta: :data, port: port)
assert IO.chardata_to_string(format) == "meta=data port=<0.1234> "
# Also works with to_string
format = format(compiled, :error, nil, nil, date: ~D[2020-10-01])
assert IO.chardata_to_string(format) == "date=2020-10-01 "