diff options
author | José Valim <jose.valim@dashbit.co> | 2022-01-05 15:34:44 +0100 |
---|---|---|
committer | José Valim <jose.valim@dashbit.co> | 2022-01-05 15:34:44 +0100 |
commit | 5792c3835fdef6fbf52fc477ef9789f96c0ec68d (patch) | |
tree | 8e716dca04662ae286fd0c216f29e47c328c5097 | |
parent | f78e43b54363de2a79d0737d488c27a024d4a0e0 (diff) | |
download | elixir-5792c3835fdef6fbf52fc477ef9789f96c0ec68d.tar.gz |
Document logger messages, closes #11546
-rw-r--r-- | lib/logger/lib/logger.ex | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/logger/lib/logger.ex b/lib/logger/lib/logger.ex index 58a31773e..718f3aa6e 100644 --- a/lib/logger/lib/logger.ex +++ b/lib/logger/lib/logger.ex @@ -61,6 +61,32 @@ defmodule Logger do be passed to backends. If your log level is set to `:alert`, only `:alert` and `:emergency` will be printed. + ## Message + + Logger can be used for logging both unstructured and structured data. + + Unstructured data is a string or a list of strings: + + Logger.info("hello world!") + Logger.info(["hello ", "world!"]) + + Structured data, also known as reports, are keyword lists and maps: + + Logger.info([new_user: user.id, account_type: :admin]) + Logger.info(%{new_user: user.id, account_type: :admin}) + + Log functions also accept an anonymous function as a message: + + Logger.info(fn -> "hello world!" end) + + The anonymous function can return a message or a tuple containing + the message and additional metadata (to be described in the next + section). + + In all cases, the arguments given to the `Logger` macros are only + evaluated if required by the current log level. The exception is + the `bare_log/3` function, which is the raw mechanism for logging. + ## Metadata Whenever a message is logged, additional information can be given |