Remove remaining vestiges of Logger support in ConfigDB/TransferTask

This commit is contained in:
Mark Felder 2024-06-19 14:29:44 -04:00
parent e0afb2c093
commit 3a8420b141
3 changed files with 3 additions and 98 deletions

View file

@ -13,13 +13,6 @@ defmodule Pleroma.Config.TransferTask do
@type env() :: :test | :benchmark | :dev | :prod
@add_backend if Version.match?(System.version(), "< 1.15.0-rc.0"),
do: &Logger.add_backend/1,
else: &LoggerBackends.add/1
@remove_backend if Version.match?(System.version(), "< 1.15.0-rc.0"),
do: &Logger.remove_backend/1,
else: &LoggerBackends.remove/1
defp reboot_time_keys,
do: [
{:pleroma, :hackney_pools},
@ -51,14 +44,9 @@ defmodule Pleroma.Config.TransferTask do
with {_, true} <- {:configurable, Config.get(:configurable_from_database)} do
# We need to restart applications for loaded settings take effect
{logger, other} =
settings =
(Repo.all(ConfigDB) ++ deleted_settings)
|> Enum.map(&merge_with_default/1)
|> Enum.split_with(fn {group, _, _, _} -> group in [:logger] end)
logger
|> Enum.sort()
|> Enum.each(&configure/1)
started_applications = Application.started_applications()
@ -71,7 +59,7 @@ defmodule Pleroma.Config.TransferTask do
[:pleroma | reject]
end
other
settings
|> Enum.map(&update/1)
|> Enum.uniq()
|> Enum.reject(&(&1 in reject))
@ -109,42 +97,6 @@ defmodule Pleroma.Config.TransferTask do
{group, key, value, merged}
end
# change logger configuration in runtime, without restart
defp configure({_, :backends, _, merged}) do
# removing current backends
Enum.each(Application.get_env(:logger, :backends), @remove_backend)
Enum.each(merged, @add_backend)
:ok = update_env(:logger, :backends, merged)
end
defp configure({_, key, _, merged})
when key in [:console, Logger.Backends.Console, :ex_syslogger] do
backend =
case key do
:ex_syslogger -> {ExSyslogger, :ex_syslogger}
:console -> Logger.Backends.Console
Logger.Backends.Console -> Logger.Backends.Console
key -> key
end
merged =
if backend == Logger.Backends.Console do
put_in(merged[:format], merged[:format] <> "\n")
else
merged
end
Logger.configure_backend(backend, merged)
:ok = update_env(:logger, key, merged)
end
defp configure({_, key, _, merged}) do
Logger.configure([{key, merged}])
:ok = update_env(:logger, key, merged)
end
defp update({group, key, value, merged}) do
try do
:ok = update_env(group, key, merged)

View file

@ -165,8 +165,7 @@ defmodule Pleroma.ConfigDB do
{:pleroma, :ecto_repos},
{:mime, :types},
{:cors_plug, [:max_age, :methods, :expose, :headers]},
{:swarm, :node_blacklist},
{:logger, :backends}
{:swarm, :node_blacklist}
]
Enum.any?(full_key_update, fn

View file

@ -609,52 +609,6 @@ defmodule Pleroma.Web.AdminAPI.ConfigControllerTest do
]
end
test "saving full setting if value is in full_key_update list", %{conn: conn} do
backends = Application.get_env(:logger, :backends)
on_exit(fn -> Application.put_env(:logger, :backends, backends) end)
insert(:config,
group: :logger,
key: :backends,
value: []
)
Pleroma.Config.TransferTask.load_and_update_env([], false)
assert Application.get_env(:logger, :backends) == []
conn =
conn
|> put_req_header("content-type", "application/json")
|> post("/api/pleroma/admin/config", %{
configs: [
%{
group: ":logger",
key: ":backends",
value: [":console"]
}
]
})
assert json_response_and_validate_schema(conn, 200) == %{
"configs" => [
%{
"group" => ":logger",
"key" => ":backends",
"value" => [
":console"
],
"db" => [":backends"]
}
],
"need_reboot" => false
}
assert Application.get_env(:logger, :backends) == [
:console
]
end
test "saving full setting if value is not keyword", %{conn: conn} do
insert(:config,
group: :tesla,