Skip to content

Commit 17a0130

Browse files
committed
More improvements to Logger metadata
1 parent db72cdd commit 17a0130

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

lib/logger/lib/logger.ex

+12-11
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ defmodule Logger do
102102
103103
Furthermore, metadata can be set per process with `Logger.metadata/1`.
104104
105-
Some metadata, however, is always added automatically by Logger
106-
whenever possible. Those are:
105+
Some metadata, however, may be added automatically by Logger whenever
106+
possible. Those are:
107107
108108
* `:application` - the current application
109109
@@ -137,13 +137,13 @@ defmodule Logger do
137137
There are two special metadata keys, `:module` and `:function`, which
138138
extract the relevant bits from `:mfa`.
139139
140-
Note that all metadata is optional and may not always be available.
141-
The `:mfa`, `:file`, `:line`, and similar metadata are automatically
142-
included when using `Logger` macros. `Logger.bare_log/3` does not include
143-
any metadata beyond the `:pid` by default. Other metadata, such as
140+
The metadata keys above may not always be available. The `:mfa`, `:file`,
141+
`:line`, and similar metadata are automatically included when using `Logger`
142+
macros, but not when using `Logger.bare_log/3`. Other metadata, such as
144143
`:crash_reason`, `:initial_call`, and `:registered_name` are available
145144
only inside behaviours such as GenServer, Supervisor, and others.
146145
146+
It is also possible to pass metadata on a particular Logger invocation.
147147
For example, you might wish to include a custom `:error_code` metadata in
148148
your logs:
149149
@@ -196,8 +196,10 @@ defmodule Logger do
196196
if `:handle_otp_reports` is true.
197197
198198
* `:metadata` - key-value pairs of global primary metadata to be included
199-
in all log messages. Defaults to `[]`. This can be overridden at the process
200-
level with `metadata/1` or each on log call as desired.
199+
in all log messages. Defaults to `[]`. The default formatter writes to
200+
standard out and therefore cannot print all metadata. See
201+
[`Logger.Formatter`'s documentation](Logger.Formatter.html#module-metadata`)
202+
for more information.
201203
202204
For example, to configure `Logger` to redirect all Erlang messages using a
203205
`config/config.exs` file:
@@ -529,9 +531,8 @@ defmodule Logger do
529531
with the exception of setting a key to `nil`, which will remove that key
530532
from the metadata.
531533
532-
Note not all keys can be set as metadata. The metadata automatically added
533-
by Logger, as declared in the module documentation, will always override
534-
custom one.
534+
Note some metadata keys are reserved and cannot be overridden. See
535+
[the module documentation](#module-metadata) for more information.
535536
"""
536537
@spec metadata(metadata) :: :ok
537538
def metadata(keyword) do

lib/logger/lib/logger/formatter.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ defmodule Logger.Formatter do
7777
7878
> #### When is user metadata printed? {: .warning}
7979
>
80-
> User's metadata must meet one of the following conditions to be printed:
80+
> The default Logger formatter requires the user's metadata to meet
81+
> one of the following conditions to be printed:
8182
>
8283
> * Be a string (`is_binary/1`)
8384
> * Be a number (either `is_integer/1` or `is_float/1`)

0 commit comments

Comments
 (0)