Skip to content

Commit

Permalink
Avoid Logger.warn deprecation working on recent Elixir versions (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomciopp authored Aug 30, 2023
1 parent 48833e3 commit 00e4517
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
3 changes: 1 addition & 2 deletions lib/x509/test/crl_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule X509.Test.CRLServer do
Simple CRL responder for use in test suites.
"""
use GenServer
require Logger

@doc """
Starts a CRL responder.
Expand Down Expand Up @@ -107,7 +106,7 @@ defmodule X509.Test.CRLServer do
{:ok, :http_eoh} ->
case Map.get(crl_map, path) do
nil ->
Logger.warn("No CRL defined for #{path}")
X509.Util.warn("No CRL defined for #{path}")
respond(socket, 404)
:gen_tcp.close(socket)

Expand Down
4 changes: 1 addition & 3 deletions lib/x509/test/suite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ defmodule X509.Test.Suite do
* `client-cert` - requires that the client present a valid certificate
"""

require Logger

defstruct [
:domain,
:key_type,
Expand Down Expand Up @@ -582,7 +580,7 @@ defmodule X509.Test.Suite do
%__MODULE__{valid: valid, chain: chain, server_key: server_key},
scenario
) do
Logger.warn("Unknown scenario: #{scenario}")
X509.Util.warn("Unknown scenario: #{scenario}")

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

require Logger

def app_version(application) do
application
|> Application.spec()
Expand All @@ -9,4 +11,16 @@ 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
3 changes: 1 addition & 2 deletions test/x509/test/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ defmodule X509.Test.ServerTest do

use ExUnit.Case
import X509.TestHelper
require Logger

#
# Client under test
Expand Down Expand Up @@ -839,7 +838,7 @@ defmodule X509.Test.ServerTest do
end
end
else
Logger.warn("ECDSA certificates can't be tested on the current OTP version")
X509.Util.warn("ECDSA certificates can't be tested on the current OTP version")
end

#
Expand Down

0 comments on commit 00e4517

Please sign in to comment.