Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add config to allow logging to console #1702

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ log_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

if env in [:test, :prod] do
if System.get_env("ENABLE_TELEMETRY", "false") in ["true", "1"] do
Expand All @@ -75,10 +78,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 @@ -96,4 +101,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
Loading