Skip to content

Commit

Permalink
[logging] Connection: include host, port, type
Browse files Browse the repository at this point in the history
To help debug failed connections to mpd, include the hostname, port, and connection type (local, inet, inet6) to help in debugging
  • Loading branch information
mroach committed Mar 5, 2019
1 parent c7df868 commit 556e315
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/paracusia/mpd_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,15 @@ defmodule Paracusia.MpdClient do
_ -> {hostname, port}
end

target_description = "#{ip_string(addr_family, hostname)}:#{port_conn} (#{addr_family})"

case :gen_tcp.connect(hostname_conn, port_conn, opts) do
{:ok, sock} ->
_ = Logger.debug("Successfully connected to #{ip_string(addr_family, hostname)}")
_ = Logger.debug("Successfully connected to #{target_description}")
sock

{:error, :econnrefused} when next_addr_idx == 0 ->
_ = Logger.error("Connection refused, retry after #{retry_after} ms.")
_ = Logger.error("Connection to #{target_description} refused, retry after #{retry_after} ms.")
:timer.sleep(retry_after)
connect_retry(addrs, port, attempt + 1, next_addr_idx, retry_after, max_attempts)

Expand All @@ -164,7 +166,7 @@ defmodule Paracusia.MpdClient do

_ =
Logger.warn(
"Connection refused for hostname #{ip_string(addr_family, hostname)}, " <>
"Connection refused for #{target_description}, " <>
"trying #{ip_string(addr_family, next_hostname)} instead."
)

Expand Down

0 comments on commit 556e315

Please sign in to comment.