Fix compatibility with Loggers in Elixir 1.15+

This commit is contained in:
Haelwenn (lanodan) Monnier 2023-12-24 10:45:29 +01:00 committed by Mark Felder
parent ba6afdb44d
commit c389ea0f42
7 changed files with 44 additions and 18 deletions

View File

@ -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",

View File

@ -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: [

View File

@ -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.

View File

@ -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

View File

@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
# 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

View File

@ -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

10
mix.exs
View File

@ -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.