Fix compatibility with Loggers in Elixir 1.15+
This commit is contained in:
parent
ba6afdb44d
commit
c389ea0f42
@ -132,6 +132,8 @@ config :pleroma, Pleroma.Web.Endpoint,
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Configures Elixir's Logger
|
# Configures Elixir's Logger
|
||||||
|
config :logger, backends: [:console]
|
||||||
|
|
||||||
config :logger, :console,
|
config :logger, :console,
|
||||||
level: :debug,
|
level: :debug,
|
||||||
format: "\n$time $metadata[$level] $message\n",
|
format: "\n$time $metadata[$level] $message\n",
|
||||||
|
@ -1237,8 +1237,8 @@ config :pleroma, :config_description, [
|
|||||||
key: :backends,
|
key: :backends,
|
||||||
type: [:atom, :tuple, :module],
|
type: [:atom, :tuple, :module],
|
||||||
description:
|
description:
|
||||||
"Where logs will be sent, :console - send logs to stdout, { ExSyslogger, :ex_syslogger } - to syslog, Quack.Logger - to Slack.",
|
"Where logs will be sent, Logger.Backends.Console - send logs to stdout, { ExSyslogger, :ex_syslogger } - to syslog.",
|
||||||
suggestions: [:console, {ExSyslogger, :ex_syslogger}]
|
suggestions: [Logger.Backends.Console, {ExSyslogger, :ex_syslogger}]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -1278,7 +1278,7 @@ config :pleroma, :config_description, [
|
|||||||
%{
|
%{
|
||||||
group: :logger,
|
group: :logger,
|
||||||
type: :group,
|
type: :group,
|
||||||
key: :console,
|
key: Logger.Backends.Console,
|
||||||
label: "Console Logger",
|
label: "Console Logger",
|
||||||
description: "Console logger settings",
|
description: "Console logger settings",
|
||||||
children: [
|
children: [
|
||||||
|
@ -36,7 +36,7 @@ config :pleroma, Pleroma.Emails.Mailer, adapter: Swoosh.Adapters.Local
|
|||||||
# different ports.
|
# different ports.
|
||||||
|
|
||||||
# Do not include timestamps in development logs
|
# 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
|
# Set a higher stacktrace during development. Avoid configuring such
|
||||||
# in production as building large stacktraces may be expensive.
|
# in production as building large stacktraces may be expensive.
|
||||||
|
@ -20,7 +20,7 @@ config :pleroma, Pleroma.Web.Endpoint,
|
|||||||
config :phoenix, serve_endpoints: true
|
config :phoenix, serve_endpoints: true
|
||||||
|
|
||||||
# Do not print debug messages in production
|
# 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
|
config :logger, :ex_syslogger, level: :info
|
||||||
|
|
||||||
# ## SSL Support
|
# ## SSL Support
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Pleroma: A lightweight social networking server
|
# 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
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Config.TransferTask do
|
defmodule Pleroma.Config.TransferTask do
|
||||||
@ -13,6 +13,13 @@ defmodule Pleroma.Config.TransferTask do
|
|||||||
|
|
||||||
@type env() :: :test | :benchmark | :dev | :prod
|
@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,
|
defp reboot_time_keys,
|
||||||
do: [
|
do: [
|
||||||
{:pleroma, :hackney_pools},
|
{:pleroma, :hackney_pools},
|
||||||
@ -105,26 +112,30 @@ defmodule Pleroma.Config.TransferTask do
|
|||||||
# change logger configuration in runtime, without restart
|
# change logger configuration in runtime, without restart
|
||||||
defp configure({_, :backends, _, merged}) do
|
defp configure({_, :backends, _, merged}) do
|
||||||
# removing current backends
|
# 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)
|
:ok = update_env(:logger, :backends, merged)
|
||||||
end
|
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 =
|
merged =
|
||||||
if key == :console do
|
if backend == Logger.Backends.Console do
|
||||||
put_in(merged[:format], merged[:format] <> "\n")
|
put_in(merged[:format], merged[:format] <> "\n")
|
||||||
else
|
else
|
||||||
merged
|
merged
|
||||||
end
|
end
|
||||||
|
|
||||||
backend =
|
|
||||||
if key == :ex_syslogger,
|
|
||||||
do: {ExSyslogger, :ex_syslogger},
|
|
||||||
else: key
|
|
||||||
|
|
||||||
Logger.configure_backend(backend, merged)
|
Logger.configure_backend(backend, merged)
|
||||||
:ok = update_env(:logger, key, merged)
|
:ok = update_env(:logger, key, merged)
|
||||||
end
|
end
|
||||||
|
@ -385,7 +385,12 @@ defmodule Pleroma.ConfigDB do
|
|||||||
|
|
||||||
@spec module_name?(String.t()) :: boolean()
|
@spec module_name?(String.t()) :: boolean()
|
||||||
def module_name?(string) do
|
def module_name?(string) do
|
||||||
Regex.match?(~r/^(Pleroma|Phoenix|Tesla|Ueberauth|Swoosh)\./, string) or
|
if String.contains?(string, ".") do
|
||||||
string in ["Oban", "Ueberauth", "ExSyslogger", "ConcurrentLimiter"]
|
[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
|
||||||
end
|
end
|
||||||
|
10
mix.exs
10
mix.exs
@ -109,6 +109,14 @@ defmodule Pleroma.Mixfile do
|
|||||||
for s <- oauth_strategy_packages, do: {String.to_atom(s), ">= 0.0.0"}
|
for s <- oauth_strategy_packages, do: {String.to_atom(s), ">= 0.0.0"}
|
||||||
end
|
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.
|
# Specifies your project dependencies.
|
||||||
#
|
#
|
||||||
# Type `mix help deps` for examples and options.
|
# Type `mix help deps` for examples and options.
|
||||||
@ -197,7 +205,7 @@ defmodule Pleroma.Mixfile do
|
|||||||
{:websockex, "~> 0.4.3", only: :test},
|
{:websockex, "~> 0.4.3", only: :test},
|
||||||
{:benchee, "~> 1.0", only: :benchmark},
|
{:benchee, "~> 1.0", only: :benchmark},
|
||||||
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}
|
{:dialyxir, "~> 1.4", only: [:dev, :test], runtime: false}
|
||||||
] ++ oauth_deps()
|
] ++ oauth_deps() ++ logger_deps()
|
||||||
end
|
end
|
||||||
|
|
||||||
# Aliases are shortcuts or tasks specific to the current project.
|
# Aliases are shortcuts or tasks specific to the current project.
|
||||||
|
Loading…
Reference in New Issue
Block a user