Skip to content

Commit

Permalink
feat: add config to allow logging to console (#1702)
Browse files Browse the repository at this point in the history
Added ENABLE_CONSOLE_LOG environment variable to allow logging to
console. ref: #1650
  • Loading branch information
yaboiishere committed Mar 28, 2024
1 parent 54b54ff commit d98b960
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions config/runtime.exs
Expand Up @@ -58,10 +58,13 @@ log_level =
_level -> nil
end

if not is_nil(log_level) do
config :logger,
level: log_level
end
enable_json_log = System.get_env("ENABLE_JSON_LOG", "false") in ["true", "1"]
enable_console_log = System.get_env("ENABLE_CONSOLE_LOG", "false") in ["true", "1"]

base_logger_backends = Application.get_env(:logger, :backends, [])

logger_backends =
if enable_console_log, do: [:console | base_logger_backends], else: base_logger_backends

formatters = %{
"datadog" => :datadog,
Expand All @@ -82,10 +85,12 @@ if env in [:test, :prod] do
port: port
end

if System.get_env("ENABLE_JSON_LOG", "false") in ["true", "1"] do
if enable_json_log do
logger_backends = [LoggerJSON | logger_backends]

config :logger,
level: log_level || :info,
backends: [LoggerJSON]
backends: logger_backends

formatter = System.get_env("JSON_LOG_FORMAT", "datadog")
opts = [metadata: [:request_id], json_encoder: Jason]
Expand All @@ -103,4 +108,8 @@ if env in [:test, :prod] do
if env == :prod do
config :ae_mdw, AeMdwWeb.Endpoint, server: true
end

config :logger,
level: log_level || :info,
backends: logger_backends
end

0 comments on commit d98b960

Please sign in to comment.