Closed bbhoss closed 1 year ago
Erlang/OTP 25 [erts-13.1.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.14.2 (compiled with Erlang/OTP 25)
macOS 13.1
I am working with :gen_tcp and sockets. I wanted to add the client socket do my Logger metadata to assist in an investigation. So I tried this
:gen_tcp
Logger.metadata(client_socket: csock) # csock is a Port
I have my Logger configured like this
config :logger, :console, format: "[$level] $message $metadata\n", metadata: [:pid, :client_socket]
when I log like this:
Logger.debug("RX Request: #{inspect(client_bin)}")
The output I receive is
[debug] RX Request: "I" pid=<0.244.0> [debug] RX Request: <<0, 0, 48>> pid=<0.244.0> [debug] RX Request: <<57, 0, 0, 0, 101>> pid=<0.244.0> [debug] RX Request: <<73, 0, 0>> pid=<0.244.0>
Converting the port to a string for the metadata works fine:
Logger.metadata(client_socket: inspect(csock))
[debug] RX Request: <<0, 0, 48, 57>> pid=<0.227.0> client_socket=#Port<0.8> [debug] RX Request: <<0, 0, 0, 101>> pid=<0.227.0> client_socket=#Port<0.8> [debug] RX Request: <<73, 0, 0, 48>> pid=<0.227.0> client_socket=#Port<0.8> [debug] RX Request: <<58, 0, 0, 0>> pid=<0.227.0> client_socket=#Port<0.8>
I should see the port converted to string like this:
It seems like the rest of the gang is covered, pids, refs, etc get converted to a string automatically, but not ports. Currently this is a silent failure. I think it's probably a one line fix that I'm happy to take on unless I'm missing something.
A PR is welcome!
Elixir and Erlang/OTP versions
Erlang/OTP 25 [erts-13.1.3] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.14.2 (compiled with Erlang/OTP 25)
Operating system
macOS 13.1
Current behavior
I am working with
:gen_tcp
and sockets. I wanted to add the client socket do my Logger metadata to assist in an investigation. So I tried thisI have my Logger configured like this
when I log like this:
The output I receive is
Converting the port to a string for the metadata works fine:
Expected behavior
I should see the port converted to string like this:
It seems like the rest of the gang is covered, pids, refs, etc get converted to a string automatically, but not ports. Currently this is a silent failure. I think it's probably a one line fix that I'm happy to take on unless I'm missing something.