From 3a8420b141c5186a02be702b59a3799ff65cf4f8 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Wed, 19 Jun 2024 14:29:44 -0400 Subject: [PATCH] Remove remaining vestiges of Logger support in ConfigDB/TransferTask --- lib/pleroma/config/transfer_task.ex | 52 +------------------ lib/pleroma/config_db.ex | 3 +- .../controllers/config_controller_test.exs | 46 ---------------- 3 files changed, 3 insertions(+), 98 deletions(-) diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex index 1210e2c9d..ffc95f144 100644 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@ -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) diff --git a/lib/pleroma/config_db.ex b/lib/pleroma/config_db.ex index b605d2843..89d3050d6 100644 --- a/lib/pleroma/config_db.ex +++ b/lib/pleroma/config_db.ex @@ -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 diff --git a/test/pleroma/web/admin_api/controllers/config_controller_test.exs b/test/pleroma/web/admin_api/controllers/config_controller_test.exs index 7b65600de..dc12155f5 100644 --- a/test/pleroma/web/admin_api/controllers/config_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/config_controller_test.exs @@ -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,