This repository contains a customizable formatter for the logger OTP application.
It currently supports a human-readable text output and a JSON output.
This application is now included in erl-mlog.
The following metadata entry are handled separately:
-
domain
: see the official documentation for more information. -
event
: a list of atoms identifying what is being logged.
In text mode, the formatter returns one or more lines of text representing the log message. Messages are prefixed with the log level, domain string (if present) and event string (if present); they are followed by the set of metadata formatted as a sequence of "key=value" strings.
In JSON mode, the formatter returns one JSON object serialized as a single line of text for each log message.
The following members are used:
-
level
: the log level string (e.g."error"
); -
domain
: the domain of the log message formatted as a string (e.g."otp.sasl"
). Optional. -
event
: if the message had anevent
metadata entry, a string representing the event. For example, if event was[http, request_received]
, the field will be formatted ashttp.request_received
. Optional. -
time
: the timestamp of the message as a microsecond UNIX timestamp. -
message
: the message string. -
data
: an object containing metadata associated with the message.
Make sure to add the application as dependency in the Rebar3 configuration file. After that, the formatter is configured as any other logger formatter, in the system configuration file.
Example:
[{kernel,
[{logger,
[{handler, default, logger_std_h,
#{level => debug,
filter_default => log,
formatter => {log_formatter, #{format => text}}}}]},
{logger_level, debug}]}].
See the logger documentation for more information.
The following options are available in the formatter configuration map:
-
debug
: print log events on the standard output; used when developing the formatter itself. -
format
: the output format, eithertext
orjson
. -
include_time
: include the time in each formatted message (text
format only). -
color
: colorize log entries (text
format only).
If you find a bug or have any question, feel free to open a GitHub issue or to contact me by email.
Please note that I do not currently review or accept any contribution.