@@ -13,16 +13,16 @@ defmodule Logger do
13
13
14
14
* Supports both message-based and structural logging.
15
15
16
+ * Integrate with Erlang's [`:logger'](`:logger`) and
17
+ support custom filters and handlers.
18
+
16
19
* Formats and truncates messages on the client
17
- to avoid clogging `Logger` backends .
20
+ to avoid clogging `Logger` handlers .
18
21
19
22
* Alternates between sync and async modes to remain
20
23
performant when required but also apply back-pressure
21
24
when under stress.
22
25
23
- * Support for custom filters and handlers as provided by
24
- Erlang's `:logger`.
25
-
26
26
* Allows overriding the logging level for a specific module,
27
27
application or process.
28
28
@@ -65,7 +65,7 @@ defmodule Logger do
65
65
66
66
For example, `:info` takes precedence over `:debug`. If your log
67
67
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
69
69
`:alert` and `:emergency` will be printed.
70
70
71
71
## Message
@@ -126,8 +126,8 @@ defmodule Logger do
126
126
* `:crash_reason` - a two-element tuple with the throw/error/exit reason
127
127
as first argument and the stacktrace as second. A throw will always be
128
128
`{: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
131
131
errors to third-party services
132
132
133
133
There are two special metadata keys, `:module` and `:function`, which
@@ -275,8 +275,8 @@ defmodule Logger do
275
275
Remember that if you want to purge log calls from a dependency, the
276
276
dependency must be recompiled.
277
277
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:
280
280
281
281
config :logger,
282
282
compile_time_purge_matching: [
@@ -300,7 +300,7 @@ defmodule Logger do
300
300
301
301
* `:level` - the logging level. Attempting to log any message
302
302
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
304
304
may have its specific level, too. In addition to levels mentioned
305
305
above it also supports 2 "meta-levels":
306
306
@@ -397,7 +397,7 @@ defmodule Logger do
397
397
Prior to Elixir v1.15, custom logging could be achieved with Logger
398
398
backends. The main API for writing Logger backends have been moved to
399
399
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
401
401
compatibility.
402
402
403
403
Important remarks:
@@ -428,9 +428,12 @@ defmodule Logger do
428
428
Backends, you can still set `backends: [Logger.Backends.Console]` and place
429
429
the configuration under `config :logger, Logger.Backends.Console`. Although
430
430
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
432
432
in future releases
433
433
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`
434
437
"""
435
438
436
439
@ type level ::
@@ -933,37 +936,21 @@ defmodule Logger do
933
936
934
937
defp add_elixir_domain ( metadata ) , do: Map . put ( metadata , :domain , [ :elixir ] )
935
938
936
- translations = % {
937
- emergency: :error ,
938
- alert: :error ,
939
- critical: :error ,
940
- notice: :info
941
- }
942
-
943
939
for level <- @ levels do
944
940
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"
956
943
957
944
@ doc """
958
- Logs a #{ level } message.
945
+ Logs #{ article } #{ level } message.
959
946
960
- Returns `:ok`.#{ extra }
947
+ Returns `:ok`.
961
948
962
949
## Examples
963
950
964
951
Logging a message (string or iodata):
965
952
966
- Logger.#{ level } ("this is a #{ level } message")
953
+ Logger.#{ level } ("this is #{ article } #{ level } message")
967
954
968
955
Report message (maps or keywords):
969
956
@@ -973,6 +960,14 @@ defmodule Logger do
973
960
# as map
974
961
Logger.#{ level } (#{ inspect ( Map . new ( report ) ) } )
975
962
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
+
976
971
"""
977
972
978
973
# Only macros generated for the "new" Erlang levels are available since 1.11.0. Other
0 commit comments