Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Logger.warning/1 when available #3

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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