Merge branch 'fix/1694-transfer-task-fix' into 'develop'

Fix for logger configuration

Closes #1694

See merge request pleroma/pleroma!2396
This commit is contained in:
Haelwenn 2020-04-17 09:02:10 +00:00
commit d8142ee6fe
2 changed files with 19 additions and 22 deletions

View file

@ -122,7 +122,7 @@ defmodule Pleroma.Config.TransferTask do
:ok = update_env(:logger, :backends, merged)
end
defp configure({group, key, _, merged}) do
defp configure({_, key, _, merged}) when key in [:console, :ex_syslogger] do
merged =
if key == :console do
put_in(merged[:format], merged[:format] <> "\n")
@ -136,7 +136,12 @@ defmodule Pleroma.Config.TransferTask do
else: key
Logger.configure_backend(backend, merged)
:ok = update_env(:logger, group, 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

View file

@ -16,6 +16,7 @@ defmodule Pleroma.Config.TransferTaskTest do
refute Application.get_env(:pleroma, :test_key)
refute Application.get_env(:idna, :test_key)
refute Application.get_env(:quack, :test_key)
initial = Application.get_env(:logger, :level)
ConfigDB.create(%{
group: ":pleroma",
@ -35,16 +36,20 @@ defmodule Pleroma.Config.TransferTaskTest do
value: [:test_value1, :test_value2]
})
ConfigDB.create(%{group: ":logger", key: ":level", value: :debug})
TransferTask.start_link([])
assert Application.get_env(:pleroma, :test_key) == [live: 2, com: 3]
assert Application.get_env(:idna, :test_key) == [live: 15, com: 35]
assert Application.get_env(:quack, :test_key) == [:test_value1, :test_value2]
assert Application.get_env(:logger, :level) == :debug
on_exit(fn ->
Application.delete_env(:pleroma, :test_key)
Application.delete_env(:idna, :test_key)
Application.delete_env(:quack, :test_key)
Application.put_env(:logger, :level, initial)
end)
end
@ -78,8 +83,8 @@ defmodule Pleroma.Config.TransferTaskTest do
end
test "transfer config values with full subkey update" do
emoji = Application.get_env(:pleroma, :emoji)
assets = Application.get_env(:pleroma, :assets)
clear_config(:emoji)
clear_config(:assets)
ConfigDB.create(%{
group: ":pleroma",
@ -99,11 +104,6 @@ defmodule Pleroma.Config.TransferTaskTest do
assert emoji_env[:groups] == [a: 1, b: 2]
assets_env = Application.get_env(:pleroma, :assets)
assert assets_env[:mascots] == [a: 1, b: 2]
on_exit(fn ->
Application.put_env(:pleroma, :emoji, emoji)
Application.put_env(:pleroma, :assets, assets)
end)
end
describe "pleroma restart" do
@ -112,8 +112,7 @@ defmodule Pleroma.Config.TransferTaskTest do
end
test "don't restart if no reboot time settings were changed" do
emoji = Application.get_env(:pleroma, :emoji)
on_exit(fn -> Application.put_env(:pleroma, :emoji, emoji) end)
clear_config(:emoji)
ConfigDB.create(%{
group: ":pleroma",
@ -128,8 +127,7 @@ defmodule Pleroma.Config.TransferTaskTest do
end
test "on reboot time key" do
chat = Application.get_env(:pleroma, :chat)
on_exit(fn -> Application.put_env(:pleroma, :chat, chat) end)
clear_config(:chat)
ConfigDB.create(%{
group: ":pleroma",
@ -141,8 +139,7 @@ defmodule Pleroma.Config.TransferTaskTest do
end
test "on reboot time subkey" do
captcha = Application.get_env(:pleroma, Pleroma.Captcha)
on_exit(fn -> Application.put_env(:pleroma, Pleroma.Captcha, captcha) end)
clear_config(Pleroma.Captcha)
ConfigDB.create(%{
group: ":pleroma",
@ -154,13 +151,8 @@ defmodule Pleroma.Config.TransferTaskTest do
end
test "don't restart pleroma on reboot time key and subkey if there is false flag" do
chat = Application.get_env(:pleroma, :chat)
captcha = Application.get_env(:pleroma, Pleroma.Captcha)
on_exit(fn ->
Application.put_env(:pleroma, :chat, chat)
Application.put_env(:pleroma, Pleroma.Captcha, captcha)
end)
clear_config(:chat)
clear_config(Pleroma.Captcha)
ConfigDB.create(%{
group: ":pleroma",