|
NAMElogger_formatter - Default formatter for Logger.DESCRIPTIONEach Logger handler has a configured formatter specified as a module and a configuration term. The purpose of the formatter is to translate the log events to a final printable string (unicode:chardata()) which can be written to the output device of the handler. See sections Handlers and Formatters in the Kernel User's Guide for more information.logger_formatter is the default formatter used by Logger. DATA TYPESconfig() = #{chars_limit => integer() >= 1 | unlimited, depth => integer() >= 1 | unlimited, legacy_header => boolean(), max_size => integer() >= 1 | unlimited, report_cb => logger:report_cb(), single_line => boolean(), template => template(), time_designator => byte(), time_offset => integer() | [byte()]} The configuration term for logger_formatter is a map, and the following keys can be set as configuration parameters:
Defaults to unlimited.
Defaults to unlimited.
Defaults to false.
Defaults to unlimited.
If this configuration parameter is set, it replaces both the default report callback, and any report callback found in metadata. That is, all reports are converted by this configured function.
Defaults to true.
Defaults to $T. The value of this parameter is used as the time_designator option to calendar:system_time_to_rcf3339/2.
An empty string is interpreted as local time. The values "Z", "z" or 0 are interpreted as Universal Coordinated Time (UTC). Strings, other than "Z", "z", or "", must be on the form ±[hh]:[mm], for example "-02:00" or "+00:00". Integers must be in microseconds, meaning that the offset 7200000000 is equivalent to "+02:00". Defaults to an empty string, meaning that timestamps are displayed in local time. However, for backwards compatibility, if the SASL configuration parameter utc_log=true, the default is changed to "Z", meaning that timestamps are displayed in UTC. The value of this parameter is used as the offset option to calendar:system_time_to_rcf3339/2. metakey() = atom() | [atom()] template() = [metakey() | {metakey(), template(), template()} | unicode:chardata()] The template is a list of atoms, atom lists, tuples and strings. The atoms level or msg, are treated as placeholders for the severity level and the log message, respectively. Other atoms or atom lists are interpreted as placeholders for metadata, where atoms are expected to match top level keys, and atom lists represent paths to sub keys when the metadata is a nested map. For example the list [key1,key2] is replaced by the value of the key2 field in the nested map below. The atom key1 on its own is replaced by the complete value of the key1 field. The values are converted to strings. #{key1 => #{key2 => my_value, ...} ...} Tuples in the template express if-exist tests for metadata keys. For example, the following tuple says that if key1 exists in the metadata map, print "key1=Value", where Value is the value that key1 is associated with in the metadata map. If key1 does not exist, print nothing. {key1, ["key1=",key1], []} Strings in the template are printed literally. The default value for the template configuration parameter depends on the value of the single_line and legacy_header configuration parameters as follows. The log event used in the examples is: ?LOG_ERROR("name: ~p~nexit_reason: ~p", [my_name, "It crashed"])
Example log entry: =ERROR REPORT==== 17-May-2018::18:30:19.453447 === name: my_name exit_reason: "It crashed" Notice that all eight levels can occur in the heading, not only ERROR, WARNING or INFO as error_logger produces. And microseconds are added at the end of the timestamp.
Notice that the template is here the same as for single_line=false, but the resulting log entry differs in that there is only one line after the heading: =ERROR REPORT==== 17-May-2018::18:31:06.952665 === name: my_name, exit_reason: "It crashed"
Example log entry: 2018-05-17T18:31:31.152864+02:00 error: name: my_name, exit_reason: "It crashed"
Example log entry: 2018-05-17T18:32:20.105422+02:00 error: name: my_name exit_reason: "It crashed" EXPORTScheck_config(Config) -> ok | {error, term()} Types: Config = config()
The function is called by Logger when the formatter configuration for a handler is set or modified. It returns ok if the configuration is valid, and {error,term()} if it is faulty. The following Logger API functions can trigger this callback:
format(LogEvent, Config) -> unicode:chardata() Types: LogEvent = logger:log_event()
Config = config() This the formatter callback function to be called from handlers. The log event is processed as follows:
SEE ALSOcalendar(3), error_logger(3), io(3), io_lib(3), logger(3), maps(3), sasl(6), unicode(3)
Visit the GSP FreeBSD Man Page Interface. |