Logging
To use logger in your module, include
1 |
|
1 |
|
Logging macros
There are several macros for the most common logging levels:
1 2 3 4 5 6 |
|
Use them in correspondence with the appropriate log level. Please be mindful of what is logged and which log level is used for it.
Logging levels
A system operator can choose the global log level by setting loglevel
in mongooseim.toml
.
Possible values are the standard syslog severity levels, plus all or none:
"all"
, "debug"
, "info"
, "notice"
, "warning"
, "error"
, "critical"
, "alert"
, "emergency"
, and "none"
.
1 2 |
|
If a user sets the log level to all
, then they would see all messages in logs.
Levels warning
and error
are the most commonly used for production systems.
Logging format
We use structured logging as inspired by Ferd's post. We also use a modified logfmt format as one of the possible default logger formatters. This format is Splunk and ELK friendly. Check the list of fields for fields documentation.
what => something_interesting
field is required.
1 2 3 4 5 6 7 8 9 10 |
|
Field user => <<"alice">>
is often used too.
A common way to name an error event is what => function_name_failed
.
For example, what => remove_user_failed
. Use the advice critically, it would
not work well for any function. Counterexample:
1 2 3 |
|
Filtering logs by module
Setting loglevel to debug
can lead to a flood of messages in logs.
To set a different loglevel for just one module, call:
1 2 |
|
This code sets the loglevel to error for all log messages, except for those generated by mod_mam
.
All messages from mod_mam
would be logged.