Skip to content

Commit

Permalink
Merge pull request #3 from sippy-platform/logger
Browse files Browse the repository at this point in the history
Use `Logger.warning/1` when available
  • Loading branch information
timothyvanderaerden authored Oct 9, 2024
2 parents df49cd8 + 9479f7f commit 2f2653b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
10 changes: 8 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import Config

config :logger,
handle_otp_reports: true,
handle_sasl_reports: true,
level: :warn
handle_sasl_reports: true

# TODO: remove when we depend on Elixir ~> 1.11.
if macro_exported?(Logger, :warning, 1) do
config :logger, level: :warning
else
config :logger, level: :warn
end

config :sasl, :sasl_error_logger, false
11 changes: 10 additions & 1 deletion lib/worker/rabbit_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ defmodule ExRabbitPool.Worker.RabbitConnection do
{:EXIT, pid, reason},
%{channels: channels, connection: conn, adapter: adapter, monitors: monitors} = state
) do
Logger.warn("[Rabbit] channel lost reason: #{inspect(reason)}")
# TODO: remove when we depend on Elixir ~> 1.11.
log_warning("[Rabbit] channel lost reason: #{inspect(reason)}")

# don't start a new channel if crashed channel doesn't belongs to the pool
# anymore, this can happen when a channel crashed or is closed when a client holds it
# so we get an `:EXIT` message and a `:checkin_channel` message in no given
Expand Down Expand Up @@ -382,4 +384,11 @@ defmodule ExRabbitPool.Worker.RabbitConnection do
defp find_monitor(monitors, ref) do
Enum.find(monitors, fn {_pid, monitor_ref} -> monitor_ref == ref end)
end

# TODO: remove when we depend on Elixir ~> 1.11.
if macro_exported?(Logger, :warning, 1) do
defp log_warning(message), do: Logger.warning(message)
else
defp log_warning(message), do: Logger.warn(message)
end
end
24 changes: 22 additions & 2 deletions test/integration/consumer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,47 @@ defmodule ExRabbitPool.ConsumerTest do

def setup_channel(%{adapter: adapter, config: config}, channel) do
config = Keyword.get(config, :options, [])
Logger.warn("Setting up channel with options: #{inspect(config)}")

# TODO: remove when we depend on Elixir ~> 1.11.
log_warning("Setting up channel with options: #{inspect(config)}")

adapter.qos(channel, config)
end

def basic_deliver(%{adapter: adapter, channel: channel}, _payload, %{delivery_tag: tag}) do
:ok = adapter.ack(channel, tag)
end

# TODO: remove when we depend on Elixir ~> 1.11.
if macro_exported?(Logger, :warning, 1) do
defp log_warning(message), do: Logger.warning(message)
else
defp log_warning(message), do: Logger.warn(message)
end
end

defmodule TestConsumerNoAck do
use ExRabbitPool.Consumer

def setup_channel(%{adapter: adapter, config: config}, channel) do
config = Keyword.get(config, :options, [])
Logger.warn("Setting up channel with options: #{inspect(config)}")

# TODO: remove when we depend on Elixir ~> 1.11.
log_warning("Setting up channel with options: #{inspect(config)}")

adapter.qos(channel, config)
end

def basic_deliver(_state, _payload, _meta) do
:ok
end

# TODO: remove when we depend on Elixir ~> 1.11.
if macro_exported?(Logger, :warning, 1) do
defp log_warning(message), do: Logger.warning(message)
else
defp log_warning(message), do: Logger.warn(message)
end
end

defmodule TestDefaultConsumer do
Expand Down
2 changes: 1 addition & 1 deletion test/worker/rabbit_connection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule ExRabbitPool.Worker.RabbitConnectionTest do
test "adds record to monitors table when checking out a channel", %{config: config} do
new_config = Keyword.update!(config, :channels, fn _ -> 1 end)
pid = start_supervised!({ConnWorker, new_config})
assert {:ok, %{pid: pid} = channel} = ConnWorker.checkout_channel(pid)
assert {:ok, %{pid: pid} = _channel} = ConnWorker.checkout_channel(pid)
%{monitors: monitors} = ConnWorker.state(pid)
assert Map.get(monitors, pid) |> is_reference()
end
Expand Down

0 comments on commit 2f2653b

Please sign in to comment.