@@ -13,16 +13,16 @@ defmodule Logger do
1313
1414 * Supports both message-based and structural logging.
1515
16+ * Integrate with Erlang's [`:logger'](`:logger`) and
17+ support custom filters and handlers.
18+
1619 * Formats and truncates messages on the client
17- to avoid clogging `Logger` backends .
20+ to avoid clogging `Logger` handlers .
1821
1922 * Alternates between sync and async modes to remain
2023 performant when required but also apply back-pressure
2124 when under stress.
2225
23- * Support for custom filters and handlers as provided by
24- Erlang's `:logger`.
25-
2626 * Allows overriding the logging level for a specific module,
2727 application or process.
2828
@@ -65,7 +65,7 @@ defmodule Logger do
6565
6666 For example, `:info` takes precedence over `:debug`. If your log
6767 level is set to `:info`, then all `:info`, `:notice` and above will
68- be passed to backends . If your log level is set to `:alert`, only
68+ be passed to handlers . If your log level is set to `:alert`, only
6969 `:alert` and `:emergency` will be printed.
7070
7171 ## Message
@@ -126,8 +126,8 @@ defmodule Logger do
126126 * `:crash_reason` - a two-element tuple with the throw/error/exit reason
127127 as first argument and the stacktrace as second. A throw will always be
128128 `{:nocatch, term}`. An error is always an `Exception` struct. All other
129- entries are exits. The console backend ignores this metadata by default
130- but it can be useful to other backends , such as the ones that report
129+ entries are exits. The default formatter ignores this metadata by default
130+ but it can be useful to certain handlers , such as the ones that report
131131 errors to third-party services
132132
133133 There are two special metadata keys, `:module` and `:function`, which
@@ -275,8 +275,8 @@ defmodule Logger do
275275 Remember that if you want to purge log calls from a dependency, the
276276 dependency must be recompiled.
277277
278- For example, to configure the `:backends` and purge all calls that happen
279- at compile time with level lower than `:info` in a `config/config.exs` file:
278+ For example, to purge all calls that happen at compile time with level
279+ lower than `:info` in a `config/config.exs` file:
280280
281281 config :logger,
282282 compile_time_purge_matching: [
@@ -300,7 +300,7 @@ defmodule Logger do
300300
301301 * `:level` - the logging level. Attempting to log any message
302302 with severity less than the configured level will simply
303- cause the message to be ignored. Keep in mind that each backend
303+ cause the message to be ignored. Keep in mind that each handler
304304 may have its specific level, too. In addition to levels mentioned
305305 above it also supports 2 "meta-levels":
306306
@@ -397,7 +397,7 @@ defmodule Logger do
397397 Prior to Elixir v1.15, custom logging could be achieved with Logger
398398 backends. The main API for writing Logger backends have been moved to
399399 the [`:logger_backends`](https://github.com/elixir-lang/logger_backends)
400- project. However, the backends are still part of Elixir for backwards
400+ project. However, the backends API are still part of Elixir for backwards
401401 compatibility.
402402
403403 Important remarks:
@@ -428,9 +428,12 @@ defmodule Logger do
428428 Backends, you can still set `backends: [Logger.Backends.Console]` and place
429429 the configuration under `config :logger, Logger.Backends.Console`. Although
430430 consider using the [`:logger_backends`](https://github.com/elixir-lang/logger_backends)
431- project in such case , as `Logger.Backends.Console` itself will be deprecated
431+ project in such cases , as `Logger.Backends.Console` itself will be deprecated
432432 in future releases
433433
434+ * `Logger.Backends` only receive `:debug`, `:info`, `:warning`, and `:error`
435+ messages. `:notice` maps to `:info`. `:warn` amps to `:warnings`.
436+ All others map to `:error`
434437 """
435438
436439 @ type level ::
@@ -933,37 +936,21 @@ defmodule Logger do
933936
934937 defp add_elixir_domain ( metadata ) , do: Map . put ( metadata , :domain , [ :elixir ] )
935938
936- translations = % {
937- emergency: :error ,
938- alert: :error ,
939- critical: :error ,
940- notice: :info
941- }
942-
943939 for level <- @ levels do
944940 report = [ something: :reported , this: level ]
945-
946- extra =
947- if translation = translations [ level ] do
948- """
949-
950-
951- This is reported as \" #{ translation } \" in Elixir's
952- logger backends for backwards compatibility reasons.
953-
954- """
955- end
941+ metadata = [ user_id: 42 , request_id: "xU32kFa" ]
942+ article = if level in [ :info , :error , :alert , :emergency ] , do: "an" , else: "a"
956943
957944 @ doc """
958- Logs a #{ level } message.
945+ Logs #{ article } #{ level } message.
959946
960- Returns `:ok`.#{ extra }
947+ Returns `:ok`.
961948
962949 ## Examples
963950
964951 Logging a message (string or iodata):
965952
966- Logger.#{ level } ("this is a #{ level } message")
953+ Logger.#{ level } ("this is #{ article } #{ level } message")
967954
968955 Report message (maps or keywords):
969956
@@ -973,6 +960,14 @@ defmodule Logger do
973960 # as map
974961 Logger.#{ level } (#{ inspect ( Map . new ( report ) ) } )
975962
963+ Report message with metadata (maps or keywords):
964+
965+ # as a keyword list
966+ Logger.#{ level } ("this is #{ article } #{ level } message", #{ inspect ( metadata ) } )
967+
968+ # as map
969+ Logger.#{ level } ("this is #{ article } #{ level } message", #{ inspect ( Map . new ( metadata ) ) } )
970+
976971 """
977972
978973 # Only macros generated for the "new" Erlang levels are available since 1.11.0. Other
0 commit comments