To use logger in your module, include
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.
A system operator can choose the global log level by setting
Possible values are the standard syslog severity levels, plus all or none:
If a user sets the log level to
all, then they would see all messages in logs.
error are the most commonly used for production systems.
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
user => <<"alice">> is often used too.
A common way to name an error event is
what => function_name_failed.
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:
This code sets the loglevel to error for all log messages, except for those generated by
All messages from
mod_mam would be logged.