Elixir 1.19: Warn on old config of :console Logger and conflicts

This commit is contained in:
Phantasm 2026-01-13 23:28:57 +01:00 • committed by Phantasm
commit aed0eb3333
2 changed files with 115 additions and 54 deletions

View file

@ -419,42 +419,102 @@ defmodule Pleroma.Config.DeprecationWarnings do
@spec check_deprecated_logger_config() :: :ok | :error @spec check_deprecated_logger_config() :: :ok | :error
def check_deprecated_logger_config do def check_deprecated_logger_config do
backend = if Application.get_env(:logger, :backends) do mix_env = Pleroma.Config.get(:env)
Logger.warning(""" config_file_name = "config/#{mix_env}.secret.exs"
!!!DEPRECATION WARNING!!! config_file = File.read(config_file_name)
Your configuration is using deprecated syntax for configuring backends of Elixir's logger.
`config :logger, backends: [...]` is deprecated syntax due to changes in Elixir.
Please update your configuration at your earliest convenience to use:
`config :logger, backends: [...]`
Pleroma's default configuration will be updated in the next release which WILL override your settings.
Note: `:console` is no longer considered a backend and is used by default, you can disable it using: config_file =
`config :logger, :default_handler: false` case config_file do
""") {:ok, contents} ->
String.split(contents, "\n", trim: true)
|> Enum.reject(fn string -> String.starts_with?(string, "#") end)
|> Enum.join("\n")
true _ ->
else false
false end
end
console = if Application.get_env(:logger, :console) do declared_deprecated_backend =
Logger.warning(""" if is_binary(config_file) do
!!!DEPRECATION WARNING!!! String.contains?(config_file, "config :logger, backends") or
Your configuration is using deprecated syntax for configuring logging to console. String.contains?(config_file, "config :logger,\n backends")
`config :logger, :console` is deprecated syntax due to changes in Elixir. else
Please update your configuration at your earliest convenience to use nil
`config :logger, default_handler` and `config :logger, :default_formatter`. end
Pleroma's default configuration will be updated in the next release which WILL override your settings.
Note: `:default_handler` is used only for the `level` setting. All other configurations go under declared_deprecated_console =
`:default_formatter`. For more info visit: https://hexdocs.pm/logger/Logger.html#module-backends-and-backwards-compatibility 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
true # We can't use Application.get_env/3, because by default default_formatter is populated
else declared_new_console =
false if is_binary(config_file) do
end 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
if backend or console, do: :error, else: :ok 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.
`config :logger, backends: [...]` is deprecated syntax due to changes in Elixir.
Please update your configuration at your earliest convenience to use:
`config :logger, backends: [...]`
Pleroma's default configuration will be updated in the next release which WILL override your settings.
Note: `:console` is no longer considered a backend and is used by default, you can disable it using:
`config :logger, :default_handler: false`
""")
true
else
false
end
console =
if declared_deprecated_console do
Logger.warning("""
!!!DEPRECATION WARNING!!!
Your configuration is using deprecated syntax for configuring logging to console.
`config :logger, :console` is deprecated syntax due to changes in Elixir.
Please update your configuration at your earliest convenience to use
`config :logger, default_handler` and `config :logger, :default_formatter`.
Pleroma's default configuration will be updated in the next release which WILL override your settings.
Note: `:default_handler` is used only for the `level` setting. All other configurations go under
`:default_formatter`. For more info visit: https://hexdocs.pm/logger/Logger.html#module-backends-and-backwards-compatibility
""")
true
else
false
end
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
end end

View file

@ -401,35 +401,36 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
end end
test "warns on deprecated syntax" do test "warns on deprecated syntax" do
log = capture_log(fn -> log =
Pleroma.Config.DeprecationWarnings.check_deprecated_logger_config() capture_log(fn ->
end) Pleroma.Config.DeprecationWarnings.check_deprecated_logger_config()
end)
assert log =~ assert log =~
""" """
!!!DEPRECATION WARNING!!! !!!DEPRECATION WARNING!!!
Your configuration is using deprecated syntax for configuring backends of Elixir's logger. Your configuration is using deprecated syntax for configuring backends of Elixir's logger.
`config :logger, backends: [...]` is deprecated syntax due to changes in Elixir. `config :logger, backends: [...]` is deprecated syntax due to changes in Elixir.
Please update your configuration at your earliest convenience to use: Please update your configuration at your earliest convenience to use:
`config :logger, backends: [...]` `config :logger, backends: [...]`
Pleroma's default configuration will be updated in the next release which WILL override your settings. Pleroma's default configuration will be updated in the next release which WILL override your settings.
Note: `:console` is no longer considered a backend and is used by default, you can disable it using: Note: `:console` is no longer considered a backend and is used by default, you can disable it using:
`config :logger, :default_handler: false` `config :logger, :default_handler: false`
""" """
assert log =~ assert log =~
""" """
!!!DEPRECATION WARNING!!! !!!DEPRECATION WARNING!!!
Your configuration is using deprecated syntax for configuring logging to console. Your configuration is using deprecated syntax for configuring logging to console.
`config :logger, :console` is deprecated syntax due to changes in Elixir. `config :logger, :console` is deprecated syntax due to changes in Elixir.
Please update your configuration at your earliest convenience to use Please update your configuration at your earliest convenience to use
`config :logger, default_handler` and `config :logger, :default_formatter`. `config :logger, default_handler` and `config :logger, :default_formatter`.
Pleroma's default configuration will be updated in the next release which WILL override your settings. Pleroma's default configuration will be updated in the next release which WILL override your settings.
Note: `:default_handler` is used only for the `level` setting. All other configurations go under Note: `:default_handler` is used only for the `level` setting. All other configurations go under
`:default_formatter`. For more info visit: https://hexdocs.pm/logger/Logger.html#module-backends-and-backwards-compatibility `:default_formatter`. For more info visit: https://hexdocs.pm/logger/Logger.html#module-backends-and-backwards-compatibility
""" """
end end
end end
end end