diff --git a/config/config.exs b/config/config.exs index a40ed28af..b0507918b 100644 --- a/config/config.exs +++ b/config/config.exs @@ -132,6 +132,8 @@ config :pleroma, Pleroma.Web.Endpoint, ] # Configures Elixir's Logger +config :logger, backends: [:console] + config :logger, :console, level: :debug, format: "\n$time $metadata[$level] $message\n", diff --git a/config/description.exs b/config/description.exs index 12beec842..9780b35a7 100644 --- a/config/description.exs +++ b/config/description.exs @@ -1237,8 +1237,8 @@ config :pleroma, :config_description, [ key: :backends, type: [:atom, :tuple, :module], description: - "Where logs will be sent, :console - send logs to stdout, { ExSyslogger, :ex_syslogger } - to syslog, Quack.Logger - to Slack.", - suggestions: [:console, {ExSyslogger, :ex_syslogger}] + "Where logs will be sent, Logger.Backends.Console - send logs to stdout, { ExSyslogger, :ex_syslogger } - to syslog.", + suggestions: [Logger.Backends.Console, {ExSyslogger, :ex_syslogger}] } ] }, @@ -1278,7 +1278,7 @@ config :pleroma, :config_description, [ %{ group: :logger, type: :group, - key: :console, + key: Logger.Backends.Console, label: "Console Logger", description: "Console logger settings", children: [ diff --git a/config/dev.exs b/config/dev.exs index f23719fe3..14cf4a6dc 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -36,7 +36,7 @@ config :pleroma, Pleroma.Emails.Mailer, adapter: Swoosh.Adapters.Local # different ports. # Do not include timestamps in development logs -config :logger, :console, format: "$metadata[$level] $message\n" +config :logger, Logger.Backends.Console, format: "$metadata[$level] $message\n" # Set a higher stacktrace during development. Avoid configuring such # in production as building large stacktraces may be expensive. diff --git a/config/prod.exs b/config/prod.exs index 968f596e0..f4a12c077 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -20,7 +20,7 @@ config :pleroma, Pleroma.Web.Endpoint, config :phoenix, serve_endpoints: true # Do not print debug messages in production -config :logger, :console, level: :info +config :logger, Logger.Backends.Console, level: :info config :logger, :ex_syslogger, level: :info # ## SSL Support diff --git a/lib/pleroma/config/transfer_task.ex b/lib/pleroma/config/transfer_task.ex index 91885347f..1210e2c9d 100644 --- a/lib/pleroma/config/transfer_task.ex +++ b/lib/pleroma/config/transfer_task.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2022 Pleroma Authors +# Copyright © 2017-2023 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Config.TransferTask do @@ -13,6 +13,13 @@ 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}, @@ -105,26 +112,30 @@ defmodule Pleroma.Config.TransferTask do # change logger configuration in runtime, without restart defp configure({_, :backends, _, merged}) do # removing current backends - Enum.each(Application.get_env(:logger, :backends), &Logger.remove_backend/1) + Enum.each(Application.get_env(:logger, :backends), @remove_backend) - Enum.each(merged, &Logger.add_backend/1) + Enum.each(merged, @add_backend) :ok = update_env(:logger, :backends, merged) end - defp configure({_, key, _, merged}) when key in [:console, :ex_syslogger] do + 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 key == :console do + if backend == Logger.Backends.Console do put_in(merged[:format], merged[:format] <> "\n") else merged end - backend = - if key == :ex_syslogger, - do: {ExSyslogger, :ex_syslogger}, - else: key - Logger.configure_backend(backend, merged) :ok = update_env(:logger, key, merged) end diff --git a/lib/pleroma/config_db.ex b/lib/pleroma/config_db.ex index e28fcb124..b605d2843 100644 --- a/lib/pleroma/config_db.ex +++ b/lib/pleroma/config_db.ex @@ -385,7 +385,12 @@ defmodule Pleroma.ConfigDB do @spec module_name?(String.t()) :: boolean() def module_name?(string) do - Regex.match?(~r/^(Pleroma|Phoenix|Tesla|Ueberauth|Swoosh)\./, string) or - string in ["Oban", "Ueberauth", "ExSyslogger", "ConcurrentLimiter"] + if String.contains?(string, ".") do + [name | _] = String.split(string, ".", parts: 2) + + name in ~w[Pleroma Phoenix Tesla Ueberauth Swoosh Logger LoggerBackends] + else + string in ~w[Oban Ueberauth ExSyslogger ConcurrentLimiter] + end end end diff --git a/mix.exs b/mix.exs index 4cadb7354..0642c3760 100644 --- a/mix.exs +++ b/mix.exs @@ -109,6 +109,14 @@ defmodule Pleroma.Mixfile do for s <- oauth_strategy_packages, do: {String.to_atom(s), ">= 0.0.0"} end + defp logger_deps do + if Version.match?(System.version(), "<1.15.0-rc.0") do + [] + else + [{:logger_backends, "~> 1.0"}] + end + end + # Specifies your project dependencies. # # Type `mix help deps` for examples and options. @@ -197,7 +205,7 @@ defmodule Pleroma.Mixfile do {:websockex, "~> 0.4.3", only: :test}, {:benchee, "~> 1.0", only: :benchmark}, {:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false} - ] ++ oauth_deps() + ] ++ oauth_deps() ++ logger_deps() end # Aliases are shortcuts or tasks specific to the current project.