From 3345a9a3cd7129e39fbd770fe92b2e8505d7cbf6 Mon Sep 17 00:00:00 2001 From: Valentin Atanasov Date: Fri, 15 Mar 2024 17:06:24 +0200 Subject: [PATCH] feat: allow logger level configuration --- config/runtime.exs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/config/runtime.exs b/config/runtime.exs index e567afd64..0234b6e1d 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -42,6 +42,26 @@ if env != :test do ] end +# Logging + +log_level = + case System.get_env("LOG_LEVEL") do + "emergency" -> :emergency + "alert" -> :alert + "critical" -> :critical + "error" -> :error + "warning" -> :warning + "notice" -> :notice + "info" -> :info + "debug" -> :debug + _ -> nil + end + +if not is_nil(log_level) do + config :logger, + level: log_level +end + if env in [:test, :prod] do if System.get_env("ENABLE_TELEMETRY", "false") in ["true", "1"] do {:ok, hostname} = :inet.gethostname() @@ -57,7 +77,7 @@ if env in [:test, :prod] do if System.get_env("ENABLE_JSON_LOG", "false") in ["true", "1"] do config :logger, - level: :info, + level: log_level || :info, backends: [LoggerJSON] formatter = System.get_env("JSON_LOG_FORMAT", "datadog")