feat(docker): allow to configure loglevel at runtime through env variable

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2023-12-06 16:11:01 +01:00
parent 9907f887c9
commit 4855af8f87
2 changed files with 44 additions and 1 deletions

View File

@@ -16,7 +16,7 @@ defmodule Mix.Tasks.Mobilizon.Common do
if mix_task?(), do: Mix.Task.run("app.config")
unless System.get_env("DEBUG") || @env == :test do
Logger.configure(level: :error)
Logger.configure(level: loglevel())
end
Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
@@ -144,4 +144,25 @@ defmodule Mix.Tasks.Mobilizon.Common do
defp format_name("Elixir.Mix.Tasks.Mobilizon." <> task_name) do
String.downcase(task_name)
end
@loglevels [
:emergency,
:alert,
:critical,
:error,
:warning,
:notice,
:info,
:debug
]
defp loglevel do
loglevel_env = System.get_env("MOBILIZON_LOGLEVEL", "error")
if loglevel_env in Enum.map(@loglevels, &to_string/1) do
String.to_existing_atom(loglevel_env)
else
:error
end
end
end