A wrapper around Erlang system logger to simply configuration.
dir
: path to the directory where log files will be created (all.log
anderror.log
). The default is current directory.level
: log level. See Erlang'slogger:level()
type description. The default isnotice
.rotate_size
: a size of a log file to trigger rotation. The default is1024*1024*10
(10 mb).rotate_count
: a maximum number of rotated files. The default is5
.logging_mode
: avail type: [single
,separate
,debug_and_error
]. Filter events in separate file by level or in single. The default isdebug_and_error
.single_line
: whether to flatten log message into single line or not. The default isfalse
.max_line_size
: truncate log message at this size. The default is1024*100
(100 kb).filesync_repeat_interval
,sync_mode_qlen
,drop_mode_qlen
,flush_qlen
: Same as inlogger_std_h(erl)
module. The defaults are correspondingly:no_repeat
,1000
,1000
and5000
.console
: Whether to log into console or not. The default isfalse
.formatter
: formatter type: eitherplain
orjson
. The default isplain
. JSON formatter formats log message into JSON Lines. The log can be viewed using jq for example. Note that the option doesn't affect console formatter (i.e. thedefault
logger handler) -- plain messages are always logged into console. In other words, JSON formatter is only used for log files.exclude_meta
: only makes sense whenformatter
is set tojson
. In this case keys listed in this option are excluded from resultingmeta
field of the logged JSON message. The default is[domain, report_cb, gl, error_logger, logger_formatter]
.print_gun_shutdown_errors
: enables logging gunnoproc
and{shutdown, normal}
error reports inshutdown_error
context from gun supervisor. Such reports occur when calling process finishes earlier than gun's connection process. This situation does not affect application therefore such reports are supressed by default.true
enables logging of these reports. Default isfalse
.
[
...
{log, [{dir, "/path/to/log/dir"},
{level, warning},
{rotate_size, 1024},
{rotate_count, 5}]}
...
]
When logged as ?LOG_DEBUG("Hello, world", [], #{msisdn => 7923423444})
the corresponding
log message for:
- JSON:
{
"timestamp": "2020-10-15T10:26:15.704095+03:00",
"severity": "debug",
"message": "Hello, world",
"line": 1929,
"file": "hello.erl",
"meta": {
"msisdn": "7923423444"
},
"erlang": {
"pid": "<0.44.0>",
"mfa": "hello:world/0"
}
}
- Plain text:
2020-10-15T10:26:15.704095+03:00 [debug] [<0.44.0> hello:world/0] [msisdn=7923423444] [hello.erl:1929] Hello, world