mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2026-02-15 17:16:57 +00:00
Elixir 1.19: Warn on old config of :console Logger and conflicts
This commit is contained in:
parent
354dfbfb31
commit
6dde9d02bb
2 changed files with 115 additions and 54 deletions
|
|
@ -419,7 +419,52 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
|||
|
||||
@spec check_deprecated_logger_config() :: :ok | :error
|
||||
def check_deprecated_logger_config do
|
||||
backend = if Application.get_env(:logger, :backends) do
|
||||
mix_env = Pleroma.Config.get(:env)
|
||||
config_file_name = "config/#{mix_env}.secret.exs"
|
||||
config_file = File.read(config_file_name)
|
||||
|
||||
config_file =
|
||||
case config_file do
|
||||
{:ok, contents} ->
|
||||
String.split(contents, "\n", trim: true)
|
||||
|> Enum.reject(fn string -> String.starts_with?(string, "#") end)
|
||||
|> Enum.join("\n")
|
||||
|
||||
_ ->
|
||||
false
|
||||
end
|
||||
|
||||
declared_deprecated_backend =
|
||||
if is_binary(config_file) do
|
||||
String.contains?(config_file, "config :logger, backends") or
|
||||
String.contains?(config_file, "config :logger,\n backends")
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
declared_deprecated_console =
|
||||
if is_binary(config_file) do
|
||||
String.contains?(config_file, "config :logger, :console") or
|
||||
String.contains?(config_file, "config :logger,\n console")
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
# We can't use Application.get_env/3, because by default default_formatter is populated
|
||||
declared_new_console =
|
||||
if is_binary(config_file) do
|
||||
String.contains?(config_file, "config :logger, :default_handler") or
|
||||
String.contains?(config_file, "config :logger,\n :default_handler") or
|
||||
String.contains?(config_file, "config :logger, :default_formatter") or
|
||||
String.contains?(config_file, "config :logger,\n :default_formatter")
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
use_new_backend_config = Pleroma.Config.get([:logger, :backends])
|
||||
|
||||
backend =
|
||||
if declared_deprecated_backend do
|
||||
Logger.warning("""
|
||||
!!!DEPRECATION WARNING!!!
|
||||
Your configuration is using deprecated syntax for configuring backends of Elixir's logger.
|
||||
|
|
@ -437,7 +482,8 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
|||
false
|
||||
end
|
||||
|
||||
console = if Application.get_env(:logger, :console) do
|
||||
console =
|
||||
if declared_deprecated_console do
|
||||
Logger.warning("""
|
||||
!!!DEPRECATION WARNING!!!
|
||||
Your configuration is using deprecated syntax for configuring logging to console.
|
||||
|
|
@ -455,6 +501,20 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
|||
false
|
||||
end
|
||||
|
||||
if backend or console, do: :error, else: :ok
|
||||
conflict =
|
||||
if (!is_nil(use_new_backend_config) and declared_deprecated_backend) or
|
||||
(declared_new_console and declared_deprecated_console) do
|
||||
Logger.warning("""
|
||||
!!!CONFIGURATION CONFLICT!!!
|
||||
Pleroma has detected that both the deprecated way of configuring Logger and the new way are defined in your configuration.
|
||||
Delete the deprecated configuration syntax.
|
||||
""")
|
||||
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
|
||||
if backend or console or conflict, do: :error, else: :ok
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -401,7 +401,8 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
|||
end
|
||||
|
||||
test "warns on deprecated syntax" do
|
||||
log = capture_log(fn ->
|
||||
log =
|
||||
capture_log(fn ->
|
||||
Pleroma.Config.DeprecationWarnings.check_deprecated_logger_config()
|
||||
end)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue