Skip to content

Commit

Permalink
Remove Logger wrappers from Utils
Browse files Browse the repository at this point in the history
Utils.warning/1 and Utils.info/1 were added to support Elixir
versions before 1.11. Since we're in the process of dropping support
for versions before 1.11, these can be removed.

This patch removes both functions and switches all calls to them to
use Logger.warning/1 and Logger.info/1 directly.
  • Loading branch information
jeffkreeftmeijer committed Jun 26, 2024
1 parent a4095cf commit 64053ae
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 36 deletions.
5 changes: 2 additions & 3 deletions lib/appsignal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ defmodule Appsignal do
use Application
alias Appsignal.Config
require Logger
import Appsignal.Utils, only: [info: 1, warning: 1]

@doc false
def start(_type, _args) do
Expand Down Expand Up @@ -87,7 +86,7 @@ defmodule Appsignal do
def initialize do
case {Config.initialize(), Config.configured_as_active?()} do
{_, false} ->
info("AppSignal disabled.")
Logger.info("AppSignal disabled.")

{:ok, true} ->
Appsignal.IntegrationLogger.debug("AppSignal starting.")
Expand All @@ -101,7 +100,7 @@ defmodule Appsignal do
end

{{:error, :invalid_config}, true} ->
warning(
Logger.warning(
"Warning: No valid AppSignal configuration found, continuing with " <>
"AppSignal metrics disabled."
)
Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/absinthe.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ defmodule Appsignal.Absinthe do

@moduledoc false

import Appsignal.Utils, only: [warning: 1]

def attach do
handlers = %{
[:absinthe, :execute, :operation, :start] => &__MODULE__.absinthe_execute_operation_start/4,
Expand All @@ -34,7 +32,7 @@ defmodule Appsignal.Absinthe do
:ok

{_, {:error, _} = error} ->
warning("Appsignal.Absinthe not attached to #{inspect(event)}: #{inspect(error)}")
Logger.warning("Appsignal.Absinthe not attached to #{inspect(event)}: #{inspect(error)}")

Check warning on line 35 in lib/appsignal/absinthe.ex

View workflow job for this annotation

GitHub Actions / test (1.13.x, 24.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 35 in lib/appsignal/absinthe.ex

View workflow job for this annotation

GitHub Actions / test (1.15.x, 26.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 35 in lib/appsignal/absinthe.ex

View workflow job for this annotation

GitHub Actions / test (1.14.x, 25.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 35 in lib/appsignal/absinthe.ex

View workflow job for this annotation

GitHub Actions / lint_dialyzer

call_to_missing

Call to missing or private function Logger.warning/1.

error
end
Expand Down
5 changes: 2 additions & 3 deletions lib/appsignal/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ defmodule Appsignal.Config do
@moduledoc false
alias Appsignal.Nif
alias Appsignal.Utils.FileSystem
import Appsignal.Utils, only: [warning: 1]

@default_config %{
active: false,
Expand Down Expand Up @@ -64,7 +63,7 @@ defmodule Appsignal.Config do
config = Map.merge(config, sources[:override])

if !empty?(config[:working_dir_path]) do
warning(fn ->
Logger.warning(fn ->

Check warning on line 66 in lib/appsignal/config.ex

View workflow job for this annotation

GitHub Actions / lint_dialyzer

call_to_missing

Call to missing or private function Logger.warning/1.
"'working_dir_path' is deprecated, please use " <>
"'working_directory_path' instead and specify the " <>
"full path to the working directory"
Expand Down Expand Up @@ -234,7 +233,7 @@ defmodule Appsignal.Config do
"all"

unknown ->
warning(
Logger.warning(

Check warning on line 236 in lib/appsignal/config.ex

View workflow job for this annotation

GitHub Actions / lint_dialyzer

call_to_missing

Call to missing or private function Logger.warning/1.
"Unknown value #{inspect(unknown)} for report_oban_errors config " <>
~s(option. Valid values are "discard", "none", "all". ) <>
~s(Defaulting to "all".)
Expand Down
4 changes: 2 additions & 2 deletions lib/appsignal/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Appsignal.Ecto do

@tracer Appsignal.Utils.compile_env(:appsignal, :appsignal_tracer, Appsignal.Tracer)
@span Appsignal.Utils.compile_env(:appsignal, :appsignal_span, Appsignal.Span)
import Appsignal.Utils, only: [module_name: 1, warning: 1]
import Appsignal.Utils, only: [module_name: 1]

@doc """
Attaches `Appsignal.Ecto` to the Ecto telemetry channel configured in the
Expand Down Expand Up @@ -34,7 +34,7 @@ defmodule Appsignal.Ecto do
:ok

{:error, _} = error ->
warning("Appsignal.Ecto not attached to #{inspect(event)}: #{inspect(error)}")
Logger.warning("Appsignal.Ecto not attached to #{inspect(event)}: #{inspect(error)}")

Check warning on line 37 in lib/appsignal/ecto.ex

View workflow job for this annotation

GitHub Actions / test (1.13.x, 24.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 37 in lib/appsignal/ecto.ex

View workflow job for this annotation

GitHub Actions / test (1.15.x, 26.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 37 in lib/appsignal/ecto.ex

View workflow job for this annotation

GitHub Actions / test (1.14.x, 25.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 37 in lib/appsignal/ecto.ex

View workflow job for this annotation

GitHub Actions / lint_dialyzer

call_to_missing

Call to missing or private function Logger.warning/1.

error
end
Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/error/backend.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ defmodule Appsignal.Error.Backend do

@behaviour :gen_event

import Appsignal.Utils, only: [warning: 1]

def init(opts), do: {:ok, opts}

def attach do
case Logger.add_backend(Appsignal.Error.Backend) do
{:error, error} ->
warning("Appsignal.Error.Backend not attached to Logger: #{error}")
Logger.warning("Appsignal.Error.Backend not attached to Logger: #{error}")

Check failure on line 16 in lib/appsignal/error/backend.ex

View workflow job for this annotation

GitHub Actions / test (1.11.x, 24.x)

** (CompileError) lib/appsignal/error/backend.ex:16: you must require Logger before invoking the macro Logger.warning/1

Check failure on line 16 in lib/appsignal/error/backend.ex

View workflow job for this annotation

GitHub Actions / test (1.12.x, 24.x)

** (CompileError) lib/appsignal/error/backend.ex:16: you must require Logger before invoking the macro Logger.warning/1

Check warning on line 16 in lib/appsignal/error/backend.ex

View workflow job for this annotation

GitHub Actions / test (1.13.x, 24.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 16 in lib/appsignal/error/backend.ex

View workflow job for this annotation

GitHub Actions / test (1.15.x, 26.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 16 in lib/appsignal/error/backend.ex

View workflow job for this annotation

GitHub Actions / test (1.14.x, 25.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 16 in lib/appsignal/error/backend.ex

View workflow job for this annotation

GitHub Actions / lint_dialyzer

call_to_missing

Call to missing or private function Logger.warning/1.
:error

_ ->
Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/finch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ defmodule Appsignal.Finch do

@moduledoc false

import Appsignal.Utils, only: [warning: 1]

def attach do
handlers = %{
[:finch, :request, :start] => &__MODULE__.finch_request_start/4,
Expand All @@ -23,7 +21,7 @@ defmodule Appsignal.Finch do
:ok

{:error, _} = error ->
warning("Appsignal.Finch not attached to #{inspect(event)}: #{inspect(error)}")
Logger.warning("Appsignal.Finch not attached to #{inspect(event)}: #{inspect(error)}")

Check warning on line 24 in lib/appsignal/finch.ex

View workflow job for this annotation

GitHub Actions / test (1.13.x, 24.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 24 in lib/appsignal/finch.ex

View workflow job for this annotation

GitHub Actions / test (1.15.x, 26.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 24 in lib/appsignal/finch.ex

View workflow job for this annotation

GitHub Actions / test (1.14.x, 25.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 24 in lib/appsignal/finch.ex

View workflow job for this annotation

GitHub Actions / lint_dialyzer

call_to_missing

Call to missing or private function Logger.warning/1.

error
end
Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/oban.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ defmodule Appsignal.Oban do

@moduledoc false

import Appsignal.Utils, only: [warning: 1]

def attach do
exception_handler =
case Appsignal.Config.report_oban_errors() do
Expand Down Expand Up @@ -42,7 +40,7 @@ defmodule Appsignal.Oban do
:ok

{_, {:error, _} = error} ->
warning("Appsignal.Oban not attached to #{inspect(event)}: #{inspect(error)}")
Logger.warning("Appsignal.Oban not attached to #{inspect(event)}: #{inspect(error)}")

Check warning on line 43 in lib/appsignal/oban.ex

View workflow job for this annotation

GitHub Actions / test (1.13.x, 24.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 43 in lib/appsignal/oban.ex

View workflow job for this annotation

GitHub Actions / lint_dialyzer

call_to_missing

Call to missing or private function Logger.warning/1.

error
end
Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/tesla.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ defmodule Appsignal.Tesla do

@moduledoc false

import Appsignal.Utils, only: [warning: 1]

def attach do
handlers = %{
[:tesla, :request, :start] => &__MODULE__.tesla_request_start/4,
Expand All @@ -23,7 +21,7 @@ defmodule Appsignal.Tesla do
:ok

{:error, _} = error ->
warning("Appsignal.Tesla not attached to #{inspect(event)}: #{inspect(error)}")
Logger.warning("Appsignal.Tesla not attached to #{inspect(event)}: #{inspect(error)}")

Check warning on line 24 in lib/appsignal/tesla.ex

View workflow job for this annotation

GitHub Actions / test (1.13.x, 24.x)

you must require Logger before invoking the macro Logger.warning/1

Check warning on line 24 in lib/appsignal/tesla.ex

View workflow job for this annotation

GitHub Actions / lint_dialyzer

call_to_missing

Call to missing or private function Logger.warning/1.

error
end
Expand Down
4 changes: 1 addition & 3 deletions lib/appsignal/transmitter.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
defmodule Appsignal.Transmitter do
@moduledoc false

import Appsignal.Utils, only: [warning: 1]

def request(method, url, headers \\ [], body \\ "") do
http_client = Application.get_env(:appsignal, :http_client, :hackney)
:application.ensure_all_started(http_client)
Expand Down Expand Up @@ -62,7 +60,7 @@ defmodule Appsignal.Transmitter do

{:error, message} ->
unless ca_file_path == packaged_ca_file_path() do
warning(
Logger.warning(

Check warning on line 63 in lib/appsignal/transmitter.ex

View workflow job for this annotation

GitHub Actions / lint_dialyzer

call_to_missing

Call to missing or private function Logger.warning/1.
"Ignoring non-existing or unreadable ca_file_path (#{ca_file_path}): #{inspect(message)}"
)
end
Expand Down
10 changes: 0 additions & 10 deletions lib/appsignal/utils.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
defmodule Appsignal.Utils do
@moduledoc false

require Logger

@doc """
Converts module name atoms to strings.
Expand All @@ -21,14 +19,6 @@ defmodule Appsignal.Utils do

def module_name(module), do: module |> to_string() |> module_name()

defdelegate info(message), to: Logger

if Version.compare(System.version(), "1.11.0") == :lt do
defdelegate warning(message), to: Logger, as: :warn
else
defdelegate warning(message), to: Logger
end

defmacro compile_env(app, key, default \\ nil) do
if Version.match?(System.version(), ">= 1.10.0") do
quote do
Expand Down

0 comments on commit 64053ae

Please sign in to comment.