Skip to content

Commit

Permalink
Don't warn on Logger.warn (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekowal authored Jun 25, 2024
1 parent 7ab3746 commit 10b33a3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
16 changes: 16 additions & 0 deletions lib/x509/logger.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
defmodule X509.Logger do
@moduledoc false
alias X509.Util

require Logger

if Util.app_version(:logger) >= [1, 11, 0] do
def warn(message, metadata \\ []) do
Logger.warning(message, metadata)
end
else
def warn(message, metadata \\ []) do
Logger.warn(message, metadata)
end
end
end
2 changes: 1 addition & 1 deletion lib/x509/test/crl_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ defmodule X509.Test.CRLServer do
{:ok, :http_eoh} ->
case Map.get(crl_map, path) do
nil ->
X509.Util.warn("No CRL defined for #{path}")
X509.Logger.warn("No CRL defined for #{path}")
respond(socket, 404)
:gen_tcp.close(socket)

Expand Down
2 changes: 1 addition & 1 deletion lib/x509/test/suite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ defmodule X509.Test.Suite do
%__MODULE__{valid: valid, chain: chain, server_key: server_key},
scenario
) do
X509.Util.warn("Unknown scenario: #{scenario}")
X509.Logger.warn("Unknown scenario: #{scenario}")

[
cert: X509.Certificate.to_der(valid),
Expand Down
14 changes: 0 additions & 14 deletions lib/x509/util.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
defmodule X509.Util do
@moduledoc false

require Logger

def app_version(application) do
application
|> Application.spec()
Expand All @@ -11,16 +9,4 @@ defmodule X509.Util do
|> String.split(".")
|> Enum.map(&String.to_integer/1)
end

# Create a utility function that handles checking for the
# existence of Logger.warning/2 if not fallback to Logger.warn/2
if macro_exported?(Logger, :warning, 2) do
def warn(message, metadata \\ []) do
Logger.warning(message, metadata)
end
else
def warn(message, metadata \\ []) do
Logger.warn(message, metadata)
end
end
end
2 changes: 1 addition & 1 deletion test/x509/test/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ defmodule X509.Test.ServerTest do
end
end
else
X509.Util.warn("ECDSA certificates can't be tested on the current OTP version")
X509.Logger.warn("ECDSA certificates can't be tested on the current OTP version")
end

#
Expand Down

0 comments on commit 10b33a3

Please sign in to comment.