summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Keele <christhekeele@gmail.com>2023-04-30 02:59:05 -0500
committerGitHub <noreply@github.com>2023-04-30 09:59:05 +0200
commitaecd523c395d3508e52e7dff0afe589fb93e07d9 (patch)
treecbf043f980c71bd64182ad83d9f3f051d4978b23
parent88e02c2ddcb23d9ec2961d3b5fcfd0e11d907f13 (diff)
downloadelixir-aecd523c395d3508e52e7dff0afe589fb93e07d9.tar.gz
Convert Logger's default_handler config into maps (#12538)
If the `:config` provided to `:default_handler` is a keyword list, we will now convert it into a map as expected by `:logger_std_h`, to support deep `Config.config` keyword list merging.
-rw-r--r--lib/logger/lib/logger.ex16
-rw-r--r--lib/logger/lib/logger/app.ex1
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/logger/lib/logger.ex b/lib/logger/lib/logger.ex
index ec2aff562..f4f1a2eee 100644
--- a/lib/logger/lib/logger.ex
+++ b/lib/logger/lib/logger.ex
@@ -174,7 +174,7 @@ defmodule Logger do
`config/config.exs`), under the `:logger` key, before your application
is started:
- * `:default_formatter` - a keyword lists which configures the
+ * `:default_formatter` - a keyword list which configures the
default formatter used by the default handler. See `Logger.Formatter`
for the full list of configuration.
@@ -213,13 +213,23 @@ defmodule Logger do
built-in support for log rotation:
config :logger, :default_handler,
- config: %{
+ config: [
file: ~c"system.log",
filesync_repeat_interval: 5000,
file_check: 5000,
max_no_bytes: 10_000_000,
max_no_files: 5
- }
+ ]
+
+ > #### Keywords or maps {: .tip}
+ >
+ > While Erlang's logger expects `:config` to be a map, Elixir's Logger
+ > allows the default handler configuration to be set with keyword lists.
+ > For example, this allows your `config/*.exs` files, such as `config/dev.exs`,
+ > to override individual keys defined in `config/config.exs`.
+ >
+ > When reading the handler configuration using Erlang's APIs,
+ > the configuration will always be read (and written) as a map.
See [`:logger_std_h`](`:logger_std_h`) for all relevant configuration,
including overload protection. Or set `:default_handler` to false to
diff --git a/lib/logger/lib/logger/app.ex b/lib/logger/lib/logger/app.ex
index cd9a79f0e..47d3db2ed 100644
--- a/lib/logger/lib/logger/app.ex
+++ b/lib/logger/lib/logger/app.ex
@@ -124,6 +124,7 @@ defmodule Logger.App do
|> Keyword.put_new(:filter_default, :log)
|> Keyword.put_new(:module, :logger_std_h)
|> Keyword.put_new_lazy(:formatter, &Logger.default_formatter/0)
+ |> Keyword.replace_lazy(:config, &Map.new/1)
|> Map.new()
case :logger.add_handler(:default, config.module, config) do