Elixir 1.19: Set merged logger config correctly, remove log level test
This commit is contained in:
parent
0ac1b65ba9
commit
1743a837dd
2 changed files with 23 additions and 36 deletions
|
|
@ -20,8 +20,7 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
||||||
"\n* `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`"}
|
"\n* `config :pleroma, :instance, mrf_transparency_exclusions` is now `config :pleroma, :mrf, transparency_exclusions`"}
|
||||||
]
|
]
|
||||||
|
|
||||||
@logger_config_knobs [:level, :translator_inspect_opts]
|
@logger_formatter_config_knobs [:colors, :format, :metadata, :truncate, :utc_log]
|
||||||
@logger_formatter_config_knows [:colors, :format, :metadata, :truncate, :utc_log]
|
|
||||||
|
|
||||||
def check_exiftool_filter do
|
def check_exiftool_filter do
|
||||||
filters = Config.get([Pleroma.Upload]) |> Keyword.get(:filters, [])
|
filters = Config.get([Pleroma.Upload]) |> Keyword.get(:filters, [])
|
||||||
|
|
@ -421,21 +420,23 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp merge_deprecated_logger_config(config) do
|
defp merge_deprecated_logger_config(config) do
|
||||||
handler_config = Enum.filter(config, fn {k, _} -> k in @logger_config_knobs end)
|
formatter_config = Enum.filter(config, fn {k, _} -> k in @logger_formatter_config_knobs end)
|
||||||
formatter_config = Enum.filter(config, fn {k, _} -> k in @logger_formatter_config_knows end)
|
|
||||||
formatter = Logger.default_formatter(formatter_config)
|
formatter = Logger.default_formatter(formatter_config)
|
||||||
|
log_level = Keyword.get(config, :level, nil)
|
||||||
|
|
||||||
Logger.debug("""
|
if Config.get(:env) != :test do
|
||||||
Reconfiguring console Logger with deprecated configuration syntax.
|
Logger.debug("""
|
||||||
Handler configuration:
|
Reconfiguring console Logger with deprecated configuration syntax.
|
||||||
#{inspect(handler_config)}
|
Handler configuration:
|
||||||
|
log_level: #{inspect(log_level)}
|
||||||
|
|
||||||
Formatter:
|
Formatter:
|
||||||
#{inspect(formatter)}
|
#{inspect(formatter)}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
Logger.configure(handler_config)
|
if log_level, do: :logger.update_handler_config(:default, :level, log_level)
|
||||||
:logger.update_handler_config(:default, :formatter, formatter)
|
:logger.update_handler_config(:default, :formatter, formatter)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec check_deprecated_logger_config() :: :ok | :error
|
@spec check_deprecated_logger_config() :: :ok | :error
|
||||||
|
|
@ -443,7 +444,7 @@ defmodule Pleroma.Config.DeprecationWarnings do
|
||||||
backends_config = Application.get_env(:logger, :backends)
|
backends_config = Application.get_env(:logger, :backends)
|
||||||
console_config = Application.get_env(:logger, :console)
|
console_config = Application.get_env(:logger, :console)
|
||||||
|
|
||||||
# Note: No need to merge the old backends config since it still works.
|
# NOTE: No need to merge the old backends config since it still works.
|
||||||
# And new configuration will just add new Logger backends.
|
# And new configuration will just add new Logger backends.
|
||||||
backend =
|
backend =
|
||||||
if backends_config do
|
if backends_config do
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Config.DeprecationWarningsTest do
|
defmodule Pleroma.Config.DeprecationWarningsTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case, async: false
|
||||||
use Pleroma.Tests.Helpers
|
use Pleroma.Tests.Helpers
|
||||||
|
|
||||||
import ExUnit.CaptureLog
|
import ExUnit.CaptureLog
|
||||||
|
|
@ -393,14 +393,15 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
||||||
|
|
||||||
describe "check_deprecated_logger_config" do
|
describe "check_deprecated_logger_config" do
|
||||||
setup do
|
setup do
|
||||||
Application.put_env(:logger, :backends, [:console, {ExSyslogger, :ex_syslogger}])
|
initial_console = Application.get_env(:logger, :console, nil)
|
||||||
Application.put_env(:logger, :console, level: :info)
|
initial_backends = Application.get_env(:logger, :backends, nil)
|
||||||
|
|
||||||
|
Application.put_env(:logger, :console, level: :all)
|
||||||
|
Application.put_env(:logger, :backends, [:console])
|
||||||
|
|
||||||
on_exit(fn ->
|
on_exit(fn ->
|
||||||
Application.delete_env(:logger, :backends)
|
if initial_console, do: Application.put_env(:logger, :console, initial_console), else: Application.delete_env(:logger, :console)
|
||||||
Application.delete_env(:logger, :console)
|
if initial_backends, do: Application.put_env(:logger, :backends, initial_backends), else: Application.delete_env(:logger, :backends)
|
||||||
Logger.configure(level: :debug)
|
|
||||||
:logger.update_handler_config(:default, :formatter, Logger.default_formatter())
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -434,20 +435,5 @@ defmodule Pleroma.Config.DeprecationWarningsTest do
|
||||||
`: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
|
||||||
|
|
||||||
test "reconfigures logger" do
|
|
||||||
empty_log =
|
|
||||||
capture_log(fn ->
|
|
||||||
Logger.debug("This should not be logged")
|
|
||||||
end)
|
|
||||||
|
|
||||||
logged =
|
|
||||||
capture_log(fn ->
|
|
||||||
Logger.info("This should be logged")
|
|
||||||
end)
|
|
||||||
|
|
||||||
assert empty_log =~ ""
|
|
||||||
assert logged =~ "This should be logged"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue