fix for logger configuration

This commit is contained in:
Alexander Strizhakov 2020-04-17 08:42:48 +03:00
parent badd888ccb
commit 304ea09f4c
No known key found for this signature in database
GPG Key ID: 022896A53AEF1381
2 changed files with 19 additions and 22 deletions

View File

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

View File

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