From 6f49591e7d5bf11d8bfc6014a0711ae59e3f3c33 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 8 May 2018 14:36:37 +0200 Subject: Update reference manuals for logger --- lib/kernel/doc/src/logger_formatter.xml | 213 ++++++++++++++++++++------------ 1 file changed, 134 insertions(+), 79 deletions(-) (limited to 'lib/kernel/doc/src/logger_formatter.xml') diff --git a/lib/kernel/doc/src/logger_formatter.xml b/lib/kernel/doc/src/logger_formatter.xml index a0940100ee..7df4c88f40 100644 --- a/lib/kernel/doc/src/logger_formatter.xml +++ b/lib/kernel/doc/src/logger_formatter.xml @@ -33,43 +33,38 @@ logger_formatter.xml logger_formatter - Default formatter for the Logger application. + Default formatter for Logger. -

Default formatter for the Logger application.

- +

Each log 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.

+

logger_formatter is the default formatter used by + Logger.

Configuration -

The following configuration parameters can be set - for logger_formatter:

+

The configuration term for logger_formatter is a map, + and the following keys can be set as configuration + parameters:

- single_line = boolean() - -

If set to true, all newlines in the message are - replaced with ", ", and whitespaces following - directly after newlines are removed. Note that newlines - added by the formatter template are not replaced.

-

Default is true.

-
- legacy_header = boolen() - -

If set to true a header field is added to - logger_formatter's part of Metadata. The value of - this field is a string similar to the header created by the - old error_logger event handlers. It can be included - in the log event by adding the - tuple {logger_formatter,header} to the - template. See Default - Templates for more information

-

Default is false.

-
- report_cb = fun((logger:report()) -> {io:format(),[term()]}) + chars_limit = pos_integer() | unlimited -

A function with arity 1, - returning {Format,Args}. This function will replace - any report_cb found in metadata.

+

A positive integer representing the value of the option + with the same name to be used when calling + io_lib:format/3. + This value limits the total number of characters printed + for each log event. Notice that this is a soft limit. For a + hard truncation limit, see option max_size.

+

Default is unlimited.

+ +

chars_limit has no effect on log messages on + string form. These are expected to be short, but can still + be truncated by the max_size parameter.

+
depth = pos_integer() | unlimited @@ -82,47 +77,79 @@ io:format/2,3 in STDLIB.

Default is unlimited.

-
- chars_limit = pos_integer() | unlimited - -

A positive integer representing the value of the option - with the same name to be used when calling - io_lib:format/3. - This value limits the total number of characters printed - for each log event. Note that this is a soft limit. For a - hard truncation limit, see option max_size.

-

Default is unlimited.

+ +

depth has no effect on log messages on string + form. These are expected to be short, but can still be + truncated by the max_size parameter.

+
max_size = pos_integer() | unlimited -

A positive integer representing the absolute maximum size - a string returned from this formatter can have. If the +

A positive integer representing the absolute maximum size a + string returned from this formatter can have. If the formatted string is longer, after possibly being limited - by depth and/or chars_limit, it will be - truncated.

+ by chars_limit or depth, it is truncated.

Default is unlimited.

+ single_line = boolean() + +

If set to true, all newlines in the message are + replaced with ", ", and whitespaces following + directly after newlines are removed. Note that newlines + added by the template parameter are not replaced.

+

Default is true.

+
+ legacy_header = boolen() + +

If set to true a header field is added to + logger_formatter's part of Metadata. The value of + this field is a string similar to the header created by the + old error_logger event handlers. It can be included + in the log event by adding the + tuple {logger_formatter,header} to the template. See + section Default + Templates for more information.

+

Default is false.

+
+ report_cb = fun((logger:report()) -> {io:format(),[term()]}) + +

A report callback is used by the formatter to transform log + messages on report form to a format string and + arguments. The report callback can be specified in the + metadata for the log event. If no report callback exist in + metadata, logger_formatter will + use + logger:format_report/1 as default + callback.

+

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.

+

The value must be a function with arity 1, + returning {Format,Args}, and it will be called with a + report as only argument.

+
template = template()

The template is a list of atoms, tuples and strings. The atoms level or msg, are treated as placeholders for the severity level and the log message, repectively. Other atoms or tuples are interpreted as - placeholders for metadata, where atoms are expected to - match top level keys, and tuples represent paths to sub - keys in a nested map. For example the - tuple {key1,key2} will be replaced by the value of + placeholders for metadata, where atoms are expected to match + top level keys, and tuples represent paths to sub keys when + the metadata is a nested map. For example the + tuple {key1,key2} is replaced by the value of the key2 field in the nested map below. The - atom key1 on its own would be replaced by the - complete value of the key1 field. The values are - converted to strings.

+ 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, ...} ...} -

Strings are printed literally.

+

Strings in the template are printed literally.

The default template differs depending on the values of legacy_header and single_line. See Default @@ -131,7 +158,8 @@ utc = boolean()

If set to true, all dates are displayed in Universal - Coordinated Time. Default is false.

+ Coordinated Time.

+

Default is false.

@@ -139,38 +167,51 @@
Default templates -

The default template when legacy_header=true is

- - [{logger_formatter,header},"\n",msg,"\n"] - -

which will cause log entries like this:

- - =ERROR REPORT==== 29-Dec-2017::13:30:51.245123 === - process: <0.74.0> - exit_reason: "Something went wrong" - -

Note that all eight levels might occur here, not - only ERROR, WARNING or INFO. And also that - micro seconds are added at the end of the timestamp.

- -

The default template when single_line=true is

- [time," ",level,": ",msg,"\n"] +

The default value for the template configuration + parameter depends on the value of single_line + and legacy_header as follows.

-

which will cause log entries like this:

+

The log event used in the examples is:

+ +?LOG_ERROR("name: ~p~nexit_reason: ~p",[my_reg_name,"It crashed"]) - 2017-12-29 13:31:49.640317 error: process: <0.74.0>, exit_reason: "Something went wrong" + + legacy_header=true + +

Default template: [{logger_formatter,header},"\n",msg,"\n"]

+ +

Example log entry:

+ +=ERROR REPORT==== 29-Dec-2017::13:30:51.245123 === +name: my_reg_name +exit_reason: "It crashed" + +

Notice that all eight levels might occur in the heading, + not only ERROR, WARNING or INFO as the + old error_logger produced. And microseconds are + added at the end of the timestamp.

+
-

The default template when both legacy_header and - single_line are set to false is:

+ single_line=true + +

Default template: [time," ",level,": ",msg,"\n"]

- [time," ",level,":\n",msg,"\n"] +

Example log entry:

+ 2017-12-29 13:31:49.640317 error: name: my_reg_name, exit_reason: "It crashed" +
-

which will cause log entries like this:

+ legacy_header=false, single_line=false + +

Default template: [time," ",level,":\n",msg,"\n"]

- 2017-12-29 13:32:25.191925 error: - process: <0.74.0> - exit_reason: "Something went wrong" +

Example log entry:

+ +2017-12-29 13:32:25.191925 error: +name: my_reg_name +exit_reason: "It crashed" +
+
@@ -186,8 +227,22 @@ Formats the given message. -

This the callback function to be called from handlers. It - formats the given messages.

+

This the formatter callback function to be called from + handlers. The log event is processed as follows:

+ + If the message is on report form, it is converted to + {Format,Args} by calling the report + callback. + The size is limited according to the values of + configuration parameters chars_limit + and depth. Notice that this does not apply to + messages on string form. + The full log entry is composed according to + the template. + If the final string is too long, it is truncated + according to the value of configuration + parameter max_size. +
-- cgit v1.2.3