From b9d2cb688e562d200663bdbedfa65adc5a29aeae Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Fri, 8 Jun 2018 14:18:36 +0200 Subject: [logger] Update documentation --- lib/kernel/doc/src/error_logger.xml | 35 +- lib/kernel/doc/src/kernel_app.xml | 117 ++-- lib/kernel/doc/src/logger.xml | 883 +++++++++++++++++-------------- lib/kernel/doc/src/logger_arch.png | Bin 32377 -> 32407 bytes lib/kernel/doc/src/logger_chapter.xml | 843 +++++++++++++++++------------ lib/kernel/doc/src/logger_disk_log_h.xml | 20 +- lib/kernel/doc/src/logger_filters.xml | 164 +++--- lib/kernel/doc/src/logger_formatter.xml | 148 ++++-- lib/kernel/doc/src/logger_std_h.xml | 21 +- lib/kernel/doc/src/part.xml | 11 +- 10 files changed, 1267 insertions(+), 975 deletions(-) (limited to 'lib/kernel/doc/src') diff --git a/lib/kernel/doc/src/error_logger.xml b/lib/kernel/doc/src/error_logger.xml index f418aa5bbe..27fb1488c7 100644 --- a/lib/kernel/doc/src/error_logger.xml +++ b/lib/kernel/doc/src/error_logger.xml @@ -305,14 +305,22 @@ ok

Enables or disables printout of standard events to a file.

-

This is done by adding or deleting the standard event handler - for output to file. Thus, calling this function overrides - the value of the Kernel error_logger configuration - parameter.

-

Enabling file logging can be used together with calling - tty(false), to have a silent system where - all standard events are logged to a file only. - Only one log file can be active at a time.

+

This is done by adding or deleting + the error_logger_file_h event handler, and thus + indirectly adding error_logger as a Logger + handler.

+

Notice that this function does not manipulate the Logger + configuration directly, meaning that if the default Logger + handler is already logging to a file, this function can + potentially cause logging to a second file.

+

This function is useful as a shortcut during development + and testing, but must not be used in a production + system. See + section Logging + in the Kernel User's Guide, and + the logger(3) + manual page for information about how to configure Logger + for live systems.

Request is one of the following:

{open, Filename} @@ -344,9 +352,14 @@ ok

Enables (Flag == true) or disables (Flag == false) printout of standard events to the terminal.

-

This is done by adding or deleting the standard event handler - for output to the terminal. Thus, calling this function overrides - the value of the Kernel error_logger configuration parameter.

+

This is done by manipulating the Logger configuration. The + function is useful as a shortcut during development and + testing, but must not be used in a production system. See + section Logging + in the Kernel User's Guide, and + the logger(3) + manual page for information about how to configure Logger + for live systems.

diff --git a/lib/kernel/doc/src/kernel_app.xml b/lib/kernel/doc/src/kernel_app.xml index e2a6d30249..3914226a3e 100644 --- a/lib/kernel/doc/src/kernel_app.xml +++ b/lib/kernel/doc/src/kernel_app.xml @@ -54,9 +54,9 @@

Two standard logger handlers are defined in the Kernel application. These are described in the Kernel User's Guide, - and in logger_std_h(3) + and in the logger_std_h(3) and logger_disk_log_h(3) - .

+ manual pages.

@@ -166,57 +166,71 @@ logger = [Config] -

Specifies how logger should be - configured.

-

For more details and examples, see the - Configuration section in the - Logger User's Guide. -

+

Specifies the configuration + for Logger, except the + primary log level, which is specified + with logger_level, + and the compatibility + with SASL Error + Logging, which is specified + with + logger_sasl_compatible.

+

The logger parameter is described in + section + Logging in the Kernel User's Guide.

logger_level = Level -

Level = emergency | alert | critical | error | warning | - notice | info | debug

-

This parameter specifies which log levels to log. The - specified level, and all levels that are more severe, will - be logged.

-

The default value is info.

-

To change the global log level at run-time, use - - logger:set_logger_config(level, error).

+

Specifies the primary log level for Logger. Log events with + the same, or a more severe level, pass through the primary + log level check. See + section Logging + in the Kernel User's Guide for more information about Logger + and log levels.

+

Level = emergency | alert | critical | error | warning | + notice | info | debug | all | none

+

To change the primary log level at runtime, use + + logger:set_primary_config(level, Level).

+

Defaults to info.

- logger_sasl_compatible = boolean() - -

If this parameter is set to true, then the default logger handler - will not log any progress-, crash-, or supervisor reports. - If the SASL application is started, - these log events will be sent to a second handler instance - named sasl, according to values of the SASL - configuration parameter sasl_error_logger - and sasl_errlog_type, see - sasl(6) -

-

The default value is false.

-

See chapter Backwards - compatibility with error_logger for more - information about handling of the so called SASL reports.

-

This configuration option only effects the default - and sasl handler. Any other handlers are uneffected.

-
- - logger_progress_reports = stop | log - -

If logger_sasl_compatible = false, - then logger_progress_reports specifies if progress - reports from supervisor - and application_controller shall be logged by the - default logger.

-

If logger_sasl_compatible = true, - then logger_progress_reports is ignored.

-

The default value is stop

-

This configuration option only effects the default - and sasl handler. Any other handlers are uneffected.

+ logger_sasl_compatible = true | false + +

Specifies if Logger behaves backwards compatible with the + SASL error logging functionality from releases prior to + Erlang/OTP 21.0.

+

If this parameter is set to true, the default Logger + handler does not log any progress-, crash-, or supervisor + reports. If the SASL application is then started, it adds a + Logger handler named sasl, which logs these events + according to values of the SASL configuration + parameter sasl_error_logger + and sasl_errlog_type.

+

See section + + Deprecated Error Logger Event Handlers and + Configuration in the sasl(6) manual page for + information about the SASL configuration parameters.

+

See section SASL Error + Logging in the SASL User's Guide, and + section Backwards + Compatibility with error_logger in the Kernel + User's Guide for information about the SASL error logging + functionality, and how Logger can be backwards compatible + with this.

+

Defaults to false.

+ +

If this parameter is set to true, + sasl_errlog_type indicates that progress reports + shall be logged, and the configured primary log level + is notice or more severe, then SASL automatically + sets the primary log level to info. That is, this + setting can potentially overwrite the value of the Kernel + configuration parameter logger_level. This is to + allow progress reports, which have log level info, + to be forwarded to the handlers.

+
global_groups = [GroupTuple] @@ -269,9 +283,8 @@ inet_parse_error_log = silent -

If set, no - logger messages are generated when erroneous - lines are found and skipped in the various Inet configuration +

If set, no log events are issued when erroneous lines are + found and skipped in the various Inet configuration files.

inetrc = Filename @@ -494,7 +507,7 @@ MaxT = TickTime + TickTime / 4 logger_std_h to the same value. Example: -erl -kernel logger '[{handler,default,logger_std_h,#{logger_std_h=>#{type=>{file,"/tmp/erlang.log"}}}}]' +erl -kernel logger '[{handler,default,logger_std_h,#{config=>#{type=>{file,"/tmp/erlang.log"}}}}]'
error_logger_format_depth diff --git a/lib/kernel/doc/src/logger.xml b/lib/kernel/doc/src/logger.xml index 911eb158da..7f35a5d752 100644 --- a/lib/kernel/doc/src/logger.xml +++ b/lib/kernel/doc/src/logger.xml @@ -33,73 +33,150 @@ logger.xml logger - API module for logging in Erlang/OTP. + API module for Logger, the standard logging facility + in Erlang/OTP. -

- This module is the main API for logging in Erlang/OTP. It - contains functions that allow applications to use a single log - API and the system to manage those log events independently. Use - the API functions or the log - macros to log events. For instance, - to log a new error event:

- -?LOG_ERROR("error happened because: ~p",[Reason]). %% With macro -logger:error("error happened because: ~p",[Reason]). %% Without macro - -

This log event is then sent to the configured log handlers which - by default means that it is be printed to the console. If you want - your systems logs to be printed to a file instead of the console you - must configure the default handler to do so. The simplest way is - to include the following in your sys.config.

+

This module implements the main API for logging in + Erlang/OTP. To create a log event, use the + API functions or the + log + macros, for example:

+ +?LOG_ERROR("error happened because: ~p", [Reason]). % With macro +logger:error("error happened because: ~p", [Reason]). % Without macro + +

To configure the Logger backend, + use Kernel configuration + parameters + or configuration + functions in the Logger API.

+ +

By default, the Kernel application installs one log handler at + system start. This handler is named default. It receives + and processes standard log events produced by the Erlang runtime + system, standard behaviours and different Erlang/OTP + applications. The log events are by default printed to the + terminal.

+

If you want your systems logs to be printed to a file instead, + you must configure the default handler to do so. The simplest + way is to include the following in + your sys.config:

[{kernel, [{logger, - [{handler,default,logger_std_h, - #{logger_std_h=>#{type=>{file,"path/to/file.log"}}}}]}]}]. + [{handler, default, logger_std_h, + #{config => #{type => {file, "path/to/file.log"}}}}]}]}].

For more information about:

- how to use the API, - see the User's Guide. - how to configure Logger, - see the Configuration + the Logger facility in general, see + the User's + Guide. + how to configure Logger, see + the Configuration section in the User's Guide. - the convinience macros in logger.hrl, - see the macro section. - what the builtin formatter can do, - see logger_formatter. - what the builtin handlers can do, + the built-in handlers, see logger_std_h and logger_disk_log_h. - what builtin filters are available, + the built-in formatter, + see logger_formatter. + built-in filters, see logger_filters.
- + -

The severity level for the message to be logged.

+

Primary configuration data for Logger. The following + default values apply:

+ + level => info + filter_default => log + filters => [] +
- + -

+

Handler configuration data for Logger. The following + default values apply:

+ + level => all + filter_default => log + filters => [] + formatter => {logger_formatter, DefaultFormatterConfig} + +

In addition to these, the following fields are + automatically inserted by Logger, values taken from the + two first parameters + to add_handler/3:

+ + id => HandlerId + module => Module + +

Handler specific configuration data is inserted by the + handler callback itself, in a sub structure associated with + the field named config.

+

See the + logger_formatter(3) manual page for + information about the default configuration for this + formatter.

- + -

+

A filter which can be installed as a handler filter, or as + a primary filter in Logger.

- + + +

The second argument to the filter fun.

+
+
+ + + +

A unique identifier for a filter.

+
+
+ + + +

The return value from the filter fun.

+
+
+ + + +

Configuration data for the + formatter. See + logger_formatter(3) + for an example of a formatter implementation.

+
+
+ + + +

A unique identifier for a handler instance.

+
+
+ + + +

The severity level for the message to be logged.

+
+
+ +

@@ -117,7 +194,7 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro

When a log macro is used, Logger also inserts location information:

- mfa => {?MODULE,?FUNCTION_NAME,?FUNCTION_ARITY} + mfa => {?MODULE, ?FUNCTION_NAME, ?FUNCTION_ARITY} file => ?FILE line => ?LINE @@ -158,51 +235,15 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro
- - -

Configuration data for the logger part of Logger, or for a handler.

-

The following default values apply:

- - level => info - filter_default => log - filters => [] - formatter => {logger_formatter,DefaultFormatterConfig} - -

See the - logger_formatter(3) manual page for - information about the default configuration for this - formatter.

-
-
- - - -

A unique identifier for a handler instance.

-
-
- - - -

A unique identifier for a filter.

-
-
- - - -

A filter which can be installed for the logger part of - Logger, or for a handler.

-
-
- - + -

The second argument to the filter fun.

+

- + -

The return value from the filter fun.

+

@@ -213,15 +254,6 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro erlang:system_time(microsecond).

- - - -

Configuration data for the - formatter. See - logger_formatter(3) - for an example of a formatter implementation.

-
-
@@ -258,6 +290,10 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro level.

+
+ + Logging API functions +
emergency(StringOrReport[,Metadata]) @@ -317,7 +353,7 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro notice(StringOrReport[,Metadata]) notice(Format,Args[,Metadata]) - notice(Fun,FunArgs[,Metadata]) + notice(Fun,FunArgs[,Metadata]) Logs the given message as level notice.

Equivalent to @@ -366,136 +402,21 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro

Log the given message.

+
+
+ + Configuration API functions +
+ - - Look up the current configuration for the logger part - of Logger. - -

Look up the current configuration for the logger part of - Logger.

-
-
- - - - Look up the current configuration for the given - handler. - -

Look up the current configuration for the given handler.

-
-
- - - - Get all Logger configurations - -

Same as logger:i(term)

-
-
- - - - - - Get all Logger configurations - -

Display or return all current Logger configurations.

- - Action = string - -

Return the pretty printed current Logger configuration - as iodata.

-
- Action = term - -

Return the current Logger configuration as a term. The - format of this term may change between releases. For a - stable format use - logger:get_handler_config/1 - and - logger:get_logger_config/0.

-

The same as calling logger:i().

-
- Action = print - -

Pretty print all the current Logger configuration to - standard out. Example:

- logger:i(print). -Current logger configuration: - Level: info - Filter Default: log - Filters: - Handlers: - Id: default - Module: logger_std_h - Level: info - Formatter: - Module: logger_formatter - Config: #{legacy_header => true,single_line => false, - template => [{logger_formatter,header},"\n",msg,"\n"]} - Filter Default: stop - Filters: - Id: stop_progress - Fun: fun logger_filters:progress/2 - Config: stop - Id: remote_gl - Fun: fun logger_filters:remote_gl/2 - Config: stop - Id: domain - Fun: fun logger_filters:domain/2 - Config: {log,super,[beam,erlang,otp,sasl]} - Id: no_domain - Fun: fun logger_filters:domain/2 - Config: {log,undefined,[]} - Handler Config: - logger_std_h: #{type => standard_io} - Level set per module: - Module: my_module - Level: debug]]> -
-
-
-
- - - - Add a filter to the logger part of Logger. + + Add a handler with the given configuration. -

Add a filter to the logger part of Logger.

-

The filter fun is called with the log event as the first - parameter, and the specified filter_args() as the - second parameter.

-

The return value of the fun specifies if a log event is to - be discarded or forwarded to the handlers:

- - log_event() - -

The filter passed. The next logger filter, if - any, is applied. If no more logger filters exist, the - log event is forwarded to the handler part of Logger, - where handler filters are applied.

-
- stop - -

The filter did not pass, and the log event is - immediately discarded.

-
- ignore - -

The filter has no knowledge of the log event. The next - logger filter, if any, is applied. If no more logger - filters exist, the value of the filter_default - configuration parameter for the logger part specifies if - the log event shall be discarded or forwarded to the - handler part.

-
-
-

See section - Filters in the User's Guide for more information - about filters.

-

Some built-in filters exist. These are defined - in logger_filters.

+

Add a handler with the given configuration.

+

HandlerId is a unique identifier which + must be used in all subsequent calls referring to this + handler.

@@ -540,99 +461,13 @@ Current logger configuration: - - - Remove a filter from the logger part of Logger. - -

Remove the filter identified - by FilterId from the logger part of Logger.

-
-
- - - - Remove a filter from the specified handler. - -

Remove the filter identified - by FilterId from the handler identified - by HandlerId.

-
-
- - - - Add a handler with the given configuration. - -

Add a handler with the given configuration.

-

HandlerId is a unique identifier which - must be used in all subsequent calls referring to this - handler.

-
-
- - - - Remove the handler with the specified identity. - -

Remove the handler identified by HandlerId.

-
-
- - - - Set the log level for the specified module. - -

Set the log level for the - specified Module.

-

The log level for a module overrides the global log level - of Logger for log events originating from the module in - question. Notice, however, that it does not override the - level configuration for any handler.

-

For example: Assume that the global log level for Logger - is info, and there is one handler, h1, with - level info and one handler, h2, with - level debug.

-

With this configuration, no debug messages will be logged, - since they are all stopped by the global log level.

-

If the level for mymodule is now set - to debug, then debug events from this module will be - logged by the handler h2, but not by - handler h1.

-

Debug events from other modules are still not logged.

-

To change the global log level for Logger, use - - logger:set_logger_config(level,Level).

-

To change the log level for a handler, use - - logger:set_handler_config(HandlerId,level,Level).

- -

The originating module for a log event is only detected - if mfa=>{Module,Function,Arity} exists in the - metadata. When log macros are used, this association is - automatically added to all log events. If an API function - is called directly, without using a macro, the logging - client must explicitly add this information if module - levels shall have any effect.

-
-
-
- - - - Remove a module specific log setting. - -

Remove a module specific log setting. After this, the - global log level is used for the specified module.

-
-
- Set up log handlers from the application's configuration parameters.

Reads the application configuration parameter logger and - calls logger:add_handlers/1 with its contents.

+ calls add_handlers/1 with its contents.

@@ -670,61 +505,158 @@ start(_, []) -> [{kernel, [{logger, %% Disable the default Kernel handler - [{handler,default,undefined}]}]}, + [{handler, default, undefined}]}]}, {my_app, [{logger, %% Enable this handler as the default - [{handler,default,my_handler,#{}}]}]}]. + [{handler, default, my_handler, #{}}]}]}]. - - Set configuration data for the logger part of Logger. + + Add a primary filter to Logger. -

Set configuration data for the logger part of Logger. This - overwrites the current logger configuration.

-

To modify the existing configuration, - use - update_logger_config/1, or, if a more - complex merge is needed, read the current configuration - with get_logger_config/0 - , then do the merge before writing the new - configuration back with this function.

-

If a key is removed compared to the current configuration, - the default value is used.

+

Add a primary filter to Logger.

+

The filter fun is called with the log event as the first + parameter, and the specified filter_args() as the + second parameter.

+

The return value of the fun specifies if a log event is to + be discarded or forwarded to the handlers:

+ + log_event() + +

The filter passed. The next primary filter, if + any, is applied. If no more primary filters exist, the + log event is forwarded to the handler part of Logger, + where handler filters are applied.

+
+ stop + +

The filter did not pass, and the log event is + immediately discarded.

+
+ ignore + +

The filter has no knowledge of the log event. The next + primary filter, if any, is applied. If no more primary + filters exist, the value of the + primary filter_default configuration parameter + specifies if the log event shall be discarded or + forwarded to the handler part.

+
+
+

See section + Filters in the User's Guide for more information + about filters.

+

Some built-in filters exist. These are defined + in logger_filters.

- - Add or update configuration data for the logger part - of Logger. + + Look up the current Logger configuration -

Add or update configuration data for the logger part of - Logger. If the given Key already exists, - its associated value will be changed - to Value. If it does not exist, it will - be added.

+

Look up all current Logger configuration, including primary + and handler configuration, and module level settings.

- - Update configuration data for the logger part of - Logger. + + Look up the current configuration for all handlers. -

Update configuration data for the logger part of - Logger. This function behaves as if it was implemented as - follows:

- -{ok,Old} = logger:get_logger_config(), -logger:set_logger_config(maps:merge(Old,Config)). - -

To overwrite the existing configuration without any merge, - use set_logger_config/1 - .

+

Look up the current configuration for all handlers.

+
+
+ + + + Look up the current configuration for the given + handler. + +

Look up the current configuration for the given handler.

+
+
+ + + + Look up the identities for all installed handlers. + +

Look up the identities for all installed handlers.

+
+
+ + + + Look up the current primary configuration for Logger. + +

Look up the current primary configuration for Logger.

+
+
+ + + + Look up all current module levels. + +

Look up all current module levels. Returns a list + containing one {Module,Level} element for each module + for which the module level was previously set + with + set_module_level/2.

+
+
+ + + + Look up the current level for the given modules. + +

Look up the current level for the given modules. Returns a + list containing one {Module,Level} element for each + of the given modules for which the module level was + previously set with + set_module_level/2.

+
+
+ + + + Retrieve data set with set_process_metadata/1. + +

Retrieve data set + with + set_process_metadata/1 or + + update_process_metadata/1.

+
+
+ + + + Remove the handler with the specified identity. + +

Remove the handler identified by HandlerId.

+
+
+ + + + Remove a filter from the specified handler. + +

Remove the filter identified + by FilterId from the handler identified + by HandlerId.

+
+
+ + + + Remove a primary filter from Logger. + +

Remove the primary filter identified + by FilterId from Logger.

@@ -763,18 +695,122 @@ logger:set_logger_config(maps:merge(Old,Config)). - - Update configuration data for the specified handler. + + Set primary configuration data for Logger. -

Update configuration data for the specified handler. This function - behaves as if it was implemented as follows:

- -{ok,{_,Old}} = logger:get_handler_config(HandlerId), -logger:set_handler_config(HandlerId,maps:merge(Old,Config)). - -

To overwrite the existing configuration without any merge, - use set_handler_config/2 +

Set primary configuration data for Logger. This + overwrites the current configuration.

+

To modify the existing configuration, + use + update_primary_config/1, or, if a more + complex merge is needed, read the current configuration + with get_primary_config/0 + , then do the merge before writing the new + configuration back with this function.

+

If a key is removed compared to the current configuration, + the default value is used.

+
+
+ + + + Add or update primary configuration data for Logger. + +

Add or update primary configuration data for Logger. If the + given Key already exists, its associated + value will be changed to Value. If it + does not exist, it will be added.

+
+
+ + + + Set the log level for the specified modules. + +

Set the log level for the + specified modules.

+

The log level for a module overrides the primary log level + of Logger for log events originating from the module in + question. Notice, however, that it does not override the + level configuration for any handler.

+

For example: Assume that the primary log level for Logger + is info, and there is one handler, h1, with + level info and one handler, h2, with + level debug.

+

With this configuration, no debug messages will be logged, + since they are all stopped by the primary log level.

+

If the level for mymodule is now set + to debug, then debug events from this module will be + logged by the handler h2, but not by + handler h1.

+

Debug events from other modules are still not logged.

+

To change the primary log level for Logger, use + + set_primary_config(level, Level).

+

To change the log level for a handler, use + + set_handler_config(HandlerId, level, Level) .

+ +

The originating module for a log event is only detected + if the key mfa exists in the metadata, and is + associated with {Module, Function, Arity}. When log + macros are used, this association is automatically added + to all log events. If an API function is called directly, + without using a macro, the logging client must explicitly + add this information if module levels shall have any + effect.

+
+
+
+ + + + Set metadata to use when logging from current process. + +

Set metadata which Logger shall automatically insert in + all log events produced on the current process.

+

Location data produced by the log macros, and/or metadata + given as argument to the log call (API function or macro), + are merged with the process metadata. If the same keys + occur, values from the metadata argument to the log call + overwrite values from the process metadata, which in turn + overwrite values from the location data.

+

Subsequent calls to this function overwrites previous data + set. To update existing data instead of overwriting it, + see + update_process_metadata/1.

+
+
+ + + + Remove module specific log settings for all modules. + +

Remove module specific log settings. After this, the + primary log level is used for all modules.

+
+
+ + + + Remove module specific log settings for the given + modules. + +

Remove module specific log settings. After this, the + primary log level is used for the specified modules.

+
+
+ + + + Delete data set with set_process_metadata/1. + +

Delete data set + with + set_process_metadata/1 or + + update_process_metadata/1.

@@ -786,9 +822,10 @@ logger:set_handler_config(HandlerId,maps:merge(Old,Config)).

The new configuration is merged with the existing formatter configuration.

To overwrite the existing configuration without any merge, - use - set_handler_config(HandlerId,formatter, - {FormatterModule,FormatterConfig}).

+ use

+
+set_handler_config(HandlerId, formatter,
+	      {FormatterModule, FormatterConfig}).
@@ -797,39 +834,41 @@ logger:set_handler_config(HandlerId,maps:merge(Old,Config)). Update the formatter configuration for the specified handler.

Update the formatter configuration for the specified handler.

-

This is equivalent - to
- update_formatter_config(HandlerId,#{Key=>Value})

+

This is equivalent to

+
+update_formatter_config(HandlerId, #{Key => Value})
- - Compare the severity of two log levels. + + Update configuration data for the specified handler. -

Compare the severity of two log levels. Returns gt - if Level1 is more severe than - Level2, lt if Level1 is less severe, - and eq if the levels are equal.

+

Update configuration data for the specified handler. This function + behaves as if it was implemented as follows:

+ +{ok, {_, Old}} = logger:get_handler_config(HandlerId), +logger:set_handler_config(HandlerId, maps:merge(Old, Config)). + +

To overwrite the existing configuration without any merge, + use set_handler_config/2 + .

- - Set metadata to use when logging from current process. + + Update primary configuration data for Logger. -

Set metadata which Logger shall automatically insert in - all log events produced on the current process.

-

Location data produced by the log macros, and/or metadata - given as argument to the log call (API function or macro), - are merged with the process metadata. If the same keys - occur, values from the metadata argument to the log call - overwrite values from the process metadata, which in turn - overwrite values from the location data.

-

Subsequent calls to this function overwrites previous data - set. To update existing data instead of overwriting it, - see - update_process_metadata/1.

+

Update primary configuration data for Logger. This function + behaves as if it was implemented as follows:

+ +Old = logger:get_primary_config(), +logger:set_primary_config(maps:merge(Old, Config)). + +

To overwrite the existing configuration without any merge, + use set_primary_config/1 + .

@@ -843,7 +882,7 @@ logger:set_handler_config(HandlerId,maps:merge(Old,Config)).

If process metadata exists for the current process, this function behaves as if it was implemented as follows:

-logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). +logger:set_process_metadata(maps:merge(logger:get_process_metadata(), Meta)).

If no process metadata exists, the function behaves as @@ -851,48 +890,44 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). .

+
+
+ + Miscellaneous API functions +
+ - - Retrieve data set with set_process_metadata/1. - -

Retrieve data set - with - set_process_metadata/1 or - - update_process_metadata/1.

-
-
- - - - Delete data set with set_process_metadata/1. + + Compare the severity of two log levels. -

Delete data set - with - set_process_metadata/1 or - - update_process_metadata/1.

+

Compare the severity of two log levels. Returns gt + if Level1 is more severe than + Level2, lt if Level1 is less severe, + and eq if the levels are equal.

- Convert a log message on report form to {Format,Args}. + Convert a log message on report form to {Format, Args}. -

Convert a log message on report form to {Format,Args}.

-

This is the default report callback used +

Convert a log message on report form to {Format, + Args}. This is the default report callback used by logger_formatter when no custom report - callback is found.

+ callback is found. See + section Log + Message in the Kernel User's Guide for + information about report callbacks and valid forms of log + messages.

The function produces lines of Key: Value from key-value lists. Strings are printed with ~ts and other terms with ~tp.

-

If the Report is a map, it is - converted to a key-value list before formatting as such.

+

If Report is a map, it is converted to + a key-value list before formatting as such.

-
@@ -904,11 +939,11 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). - HModule:adding_handler(Config1) -> {ok,Config2} | {error,Reason} + HModule:adding_handler(Config1) -> {ok, Config2} | {error, Reason} An instance of this handler is about to be added. Config1 = Config2 = - config() + handler_config() Reason = term() @@ -928,11 +963,11 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). - HModule:changing_config(Config1,Config2) -> {ok,Config3} | {error,Reason} + HModule:changing_config(Config1, Config2) -> {ok, Config3} | {error, Reason} The configuration for this handler is about to change. Config1 = Config2 = Config3 = - config() + handler_config() Reason = term() @@ -952,17 +987,17 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). - HModule:log(LogEvent,Config) -> void() + HModule:log(LogEvent, Config) -> void() Log the given log event. LogEvent = log_event() Config = - config() + handler_config()

This callback function is mandatory.

-

The function is called when all global filters and all +

The function is called when all primary filters and all handler filters for the handler in question have passed for the given log event.

The handler identity is associated with the id key @@ -978,7 +1013,7 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). The given handler is about to be removed. Config = - config() + handler_config()

This callback function is optional.

@@ -1002,18 +1037,30 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). - FModule:check_config(FConfig) -> ok | {error,term()} + FModule:check_config(FConfig) -> ok | {error, Reason} Validate the given formatter configuration. FConfig = formatter_config() + Reason = term()

This callback function is optional.

The function is called by a Logger when formatter configuration is set or modified. The formatter must validate the given configuration and return ok if it - is correct, and {error,term()} if it is faulty.

+ is correct, and {error,Reason} if it is faulty.

+

The following Logger API functions can trigger this callback:

+ + + logger:add_handler/3 + + logger:set_handler_config/2,3 + + logger:updata_handler_config/2 + + logger:update_formatter_config/2 +

See logger_formatter(3) for an example implementation. logger_formatter is the @@ -1021,7 +1068,7 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). - FModule:format(LogEvent,FConfig) -> FormattedLogEntry + FModule:format(LogEvent, FConfig) -> FormattedLogEntry Format the given log event. LogEvent = @@ -1045,6 +1092,20 @@ logger:set_process_metadata(maps:merge(logger:get_process_metadata(),Meta)). + +

+ See Also +

+ config(4), + erlang(3), + io(3), + logger_disk_log_h(3), + logger_filters(3), + logger_formatter(3), + logger_std_h(3), + unicode(3) +

+
diff --git a/lib/kernel/doc/src/logger_arch.png b/lib/kernel/doc/src/logger_arch.png index 901122193a..a9b9a658b4 100644 Binary files a/lib/kernel/doc/src/logger_arch.png and b/lib/kernel/doc/src/logger_arch.png differ diff --git a/lib/kernel/doc/src/logger_chapter.xml b/lib/kernel/doc/src/logger_chapter.xml index a3eec7bd4b..f7df0a3e6e 100644 --- a/lib/kernel/doc/src/logger_chapter.xml +++ b/lib/kernel/doc/src/logger_chapter.xml @@ -30,7 +30,7 @@ logger_chapter.xml -

Erlang/OTP 21.0 provides a new standard API for logging +

Erlang/OTP 21.0 provides a standard API for logging through Logger, which is part of the Kernel application. Logger consists of the API for issuing log events, and a customizable backend where log handlers, filters and @@ -44,7 +44,7 @@

You can also configure the system so that the default handler prints log events to a single file, or to a set of wrap logs via disk_log.

-

By confiugration, you can aslo modify or disable the default +

By configuration, you can also modify or disable the default handler, replace it by a custom handler, and install additional handlers.

@@ -53,11 +53,12 @@

A log event consists of a log level, the message to be logged, and metadata.

The Logger backend forwards log events from the API, first - through a set of global filters, then through a set - of handler filters for each log handler.

+ through a set of primary filters, then through a set of + secondary filters attached to each log handler. The secondary + filters are in the following named handler filters.

Each filter set consists of a log level check, followed by zero or more filter functions.

-

The following figure show a conseptual overview of Logger. The +

The following figure shows a conceptual overview of Logger. The figure shows two log handlers, but any number of handlers can be installed.

@@ -69,11 +70,11 @@ atoms are mapped to integer values, and a log event passes the log level check if the integer value of its log level is less than or equal to the currently configured log level. That is, - the check pases if the event is equally or more severe than the + the check passes if the event is equally or more severe than the configured level. See section Log Level for a listing and description of all log levels.

-

The global log level can be overridden by a log level +

The primary log level can be overridden by a log level configured per module. This is to, for instance, allow more verbose logging from a specific part of the system.

Filter functions can be used for more sophisticated filtering @@ -82,7 +83,7 @@ also modify all parts of the log event. See see section Filters for more details.

-

If a log event passes through all global filters and all +

If a log event passes through all primary filters and all handler filters for a specific handler, Logger forwards the event to the handler callback. The handler formats and prints the event to its destination. See @@ -107,7 +108,7 @@ functions is that macros add location (originator) information to the metadata, and performs lazy evaluation by wrapping the logger call in a case statement, so it is only evaluated if the - log level of the event passes the global log level check.

+ log level of the event passes the primary log level check.

Log Level @@ -136,7 +137,7 @@ critical 2 - critical contidions + critical conditions error @@ -178,9 +179,9 @@ message can consist of a format string and arguments (given as two separate parameters in the Logger API), a string or a report. The latter, which is either a map or a key-value list, - can be accompanied by a report callback specified in the log - event's metadata. The - report callback is a convenience function that + can be accompanied by a report callback specified in + the log event's metadata. + The report callback is a convenience function that the formatter can use to convert the report to a format string and arguments. The formatter can also use its own conversion function, if no @@ -195,7 +196,7 @@ logger:debug(#{got => connection_request, id => Id, state => State}, #{report_cb => fun(R) -> {"~p",[R]} end})

The log message can also be provided through a fun for lazy - evaluation. The fun is only evaluated if the global log level + evaluation. The fun is only evaluated if the primary log level check passes, and is therefore recommended if it is expensive to generate the message. The lazy fun must return a string, a report, or a tuple with format string and arguments.

@@ -217,9 +218,9 @@ logger:debug(#{got => connection_request, id => Id, state => State}, which these calls are made, and Logger adds the metadata to all log events issued on that process.

- Add metadata to a specifc log event + Add metadata to a specific log event -

Metadata associated with one specifc log event is given +

Metadata associated with one specific log event is given as the last parameter to the log macro or Logger API function when the event is issued. For example:

?LOG_ERROR("Connection closed",#{context => server}) @@ -235,8 +236,8 @@ logger:debug(#{got => connection_request, id => Id, state => State},
Filters -

Filters can be global, or attached to a specific - handler. Logger calls the global filters first, and if they all +

Filters can be primary, or attached to a specific + handler. Logger calls the primary filters first, and if they all pass, it calls the handler filters for each handler. Logger calls the handler callback only if all filters attached to the handler in question also pass.

@@ -251,7 +252,7 @@ logger:debug(#{got => connection_request, id => Id, state => State},

The filter function can return stop, ignore or the (possibly modified) log event.

If stop is returned, the log event is immediately - discarded. If the filter is global, no handler filters or + discarded. If the filter is primary, no handler filters or callbacks are called. If it is a handler filter, the corresponding handler callback is not called, but the log event is forwarded to filters attached to the next handler, if @@ -265,23 +266,21 @@ logger:debug(#{got => connection_request, id => Id, state => State},

If the filter function returns ignore, it means that it did not recognize the log event, and thus leaves to other filters to decide the event's destiny.

-

The configuration - option filter_default - specifies the behaviour if all filter functions - return ignore, or if no filters - exist. filter_default is by default set to log, - meaning that if all existing filters ignore a log event, Logger - forwards the event to the handler +

The configuration option filter_default specifies the + behaviour if all filter functions return ignore, or if no + filters exist. filter_default is by default set + to log, meaning that if all existing filters ignore a log + event, Logger forwards the event to the handler callback. If filter_default is set to stop, Logger discards such events.

-

Global filters are added - with - logger:add_logger_filter/2 +

Primary filters are added + with + logger:add_primary_filter/2 and removed - with - logger:remove_logger_filter/1. They can also + with + logger:remove_primary_filter/1. They can also be added at system start via the Kernel configuration - parameter logger.

+ parameter logger.

Handler filters are added with logger:add_handler_filter/3 @@ -292,12 +291,13 @@ logger:debug(#{got => connection_request, id => Id, state => State}, with logger:add_handler/3 or via the Kernel configuration - parameter logger.

+ parameter logger.

To see which filters are currently installed in the system, - use logger:i/0, - or - logger:get_logger_config/0 + use + logger:get_config/0, + or + logger:get_primary_config/0 and logger:get_handler_config/1. Filters are listed in the order they are applied, that is, the first @@ -342,7 +342,7 @@ logger:debug(#{got => connection_request, id => Id, state => State},

log(LogEvent, Config) -> void()

This function is called when a log event has passed through all - global filters, and all handler filters attached to the handler + primary filters, and all handler filters attached to the handler in question. The function call is executed on the client process, and it is up to the handler implementation if other processes are involved or not.

@@ -358,8 +358,8 @@ logger:debug(#{got => connection_request, id => Id, state => State}, functions adding_handler/1, changing_config/2 and removing_handler/1. See section Handler - Callback Functions in the logger(3) manual for more - information about these function.

+ Callback Functions in the logger(3) manual page for + more information about these function.

The following built-in handlers exist:

@@ -404,7 +404,7 @@ logger:debug(#{got => connection_request, id => Id, state => State}, which is passed as the second argument to HModule:log/2.

-

The formatter information consits of a formatter +

The formatter information consist of a formatter module, FModule and its configuration, FConfig. FModule must export the following function, which can be called by the handler:

@@ -425,152 +425,92 @@ logger:debug(#{got => connection_request, id => Id, state => State}, function when the formatter information is set or modified, to verify the validity of the formatter configuration.

If no formatter information is specified for a handler, Logger - uses - logger_formatter(3) as default.

+ uses logger_formatter as default. See + the logger_formatter(3) + manual page for more information about this module.

Configuration -

Logger can be configured either when the system starts through - configuration parameters, - or at run-time by using the logger(3) - API. The recommended approach is to do the initial configuration in - the sys.config file and then use the API when some configuration - has to be changed at runtime, such as the log level.

+

At system start, Logger is configured through Kernel + configuration parameters. The parameters that apply to Logger + are described in + section Kernel + Configuration Parameters. Examples are found in + section Configuration + Examples.

+

During runtime, Logger configuration is changed via API + functions. See + section Configuration + API Functions in the logger(3) manual page.

- Kernel Configuration Parameters -

Logger is best configured by using the configuration parameters - of Kernel. There are four possible configuration parameters: - logger, - logger_level, - logger_sasl_compatible and - logger_progress_reports. - logger_level, logger_sasl_compatible and logger_progress_reports are described in the - Kernel Configuration, - while logger is described below.

- - -

logger

-

The application configuration parameter logger is used to configure - three different Logger aspects; handlers, logger filters and module levels. - The configuration is a list containing tagged tuples that look like this:

- - DisableHandler = {handler,default,undefined} - -

Disable the default handler. This allows another application - to add its own default handler. See - logger:add_handlers/1 for more details.

-

Only one entry of this option is allowed.

- AddHandler = {handler,HandlerId,Module,HandlerConfig} - -

Add a handler as if - logger:add_handler(HandlerId,Module,HandlerConfig) is - called.

-

It is allowed to have multiple entries of this option.

- Filters = {filters, default, [Filter]}
- FilterDefault = log | stop
- Filter = {FilterId, {FilterFun, FilterConfig}}
- -

Add the specified - logger filters.

-

Only one entry of this option is allowed.

- ModuleLevel = {module_level, Level, [Module]} - -

This option configures - module log level.

-

It is allowed to have multiple entries of this option.

-
-

Examples:

- - -

Output logs into the file "logs/erlang.log"

- -[{kernel, - [{logger, - [{handler, default, logger_std_h, - #{ logger_std_h => #{ type => {file,"log/erlang.log"}}}}]}]}]. - -
- -

Output logs in single line format

- -[{kernel, - [{logger, - [{handler, default, logger_std_h, - #{ formatter => { logger_formatter,#{ single_line => true}}}}]}]}]. - -
- -

Add the pid to each log event

- -[{kernel, - [{logger, - [{handler, default, logger_std_h, - #{ formatter => { logger_formatter, - #{ template => [time," ",pid," ",msg,"\n"]}} - }}]}]}]. - -
- -

Use a different file for debug logging

- -[{kernel, - [{logger, - [{handler, default, logger_std_h, - #{ level => error, - logger_std_h => #{ type => {file, "log/erlang.log"}}}}, - {handler, info, logger_std_h, - #{ level => debug, - logger_std_h => #{ type => {file, "log/debug.log"}}}} - ]}]}]. - -
-
-
- -
- Global Logger Configuration - + Primary Logger Configuration +

Logger API functions that apply to the primary Logger + configuration are:

+ + + get_primary_config/0 + + set_primary_config/1,2 + + update_primary_config/1 + + add_primary_filter/2 + + remove_primary_filter/1 + +

The primary Logger configuration is a map with the following + keys:

- level = - logger:level() + + level = + logger:level() | all | none -

Specifies the global log level to log.

+

Specifies the primary log level, that is, log event that + are equally or more severe than this level, are forwarded + to the primary filters. Less severe log events are + immediately discarded.

See section Log Level for a listing and description of possible log levels.

The initial value of this option is set by the Kernel - configuration - parameter - logger_level. It can be changed during - runtime - with - logger:set_logger_config(level,NewLevel).

+ configuration parameter + logger_level. It is changed during + runtime with + logger:set_primary_config(level,Level).

+

Defaults to info.

- filters = [{ - logger:filter_id(), - - logger:filter()}] + filters = [{FilterId,Filter}] -

Global filters are added and removed with - - logger:add_logger_filter/2 and - - logger:remove_logger_filter/1, +

Specifies the primary filters.

+ + FilterId = + logger:filter_id() + Filter = + logger:filter() + +

The initial value of this option is set by the Kernel + configuration + parameter logger. + During runtime, primary filters are added and removed with + + logger:add_primary_filter/2 and + + logger:remove_primary_filter/1, respectively.

See section Filters - for more information.

-

Default is [], that is, no filters exist.

+ for more detailed information.

+

Defaults to [].

- filter_default = log | stop + filter_default = log | stop -

Specifies what to do with an event if all filters +

Specifies what happens to a log event if all filters return ignore, or if no filters exist.

See section Filters for more information about how this option is used.

-

Default is log.

+

Defaults to log.

@@ -578,26 +518,64 @@ logger:debug(#{got => connection_request, id => Id, state => State},
Handler Configuration +

Logger API functions that apply to handler configuration + are:

+ + + get_handler_config/0,1 + + set_handler_config/2,3 + + update_handler_config/2 + + add_handler_filter/3 + + remove_handler_filter/2 + + update_formatter_config/2,3 + +

The configuration for a handler is a map with the following keys:

+ id = + logger:handler_id() + +

Automatically inserted by Logger. The value is the same + as the HandlerId specified when adding the handler, + and it cannot be changed.

+
+ module = module() + +

Automatically inserted by Logger. The value is the same + as the Module specified when adding the handler, + and it cannot be changed.

+
level = - logger:level() + logger:level() | all | none -

Specifies the log level which the handler logs.

+

Specifies the log level for the handler, that is, log + events that are equally or more severe than this level, + are forwarded to the handler filters for this + handler.

See section Log Level for a listing and description of possible log levels.

-

The log level can be specified when adding the handler, - or changed during runtime with, for +

The log level is specified when adding the handler, or + changed during runtime with, for instance, - logger:set_handler_config/3.

-

Default is info.

+ logger:set_handler_config(HandlerId,level,Level). +

+

Defaults to all.

- filters = [{ - logger:filter_id(), - - logger:filter()}] + filters = [{FilterId,Filter}] -

Handler filters can be specified when adding the handler, +

Specifies the handler filters.

+ + FilterId = + logger:filter_id() + Filter = + logger:filter() + +

Handler filters are specified when adding the handler, or added or removed during runtime with logger:add_handler_filter/3 and @@ -605,49 +583,214 @@ logger:debug(#{got => connection_request, id => Id, state => State}, logger:remove_handler_filter/2, respectively.

See Filters for more - information.

-

Default is [], that is, no filters exist.

+ detailed information.

+

Defaults to [].

- filter_default = log | stop + filter_default = log | stop -

Specifies what to do with an event if all filters +

Specifies what happens to a log event if all filters return ignore, or if no filters exist.

See section Filters for more information about how this option is used.

-

Default is log.

+

Defaults to log.

- formatter = {module(), - logger:formatter_config()} + formatter = {FormatterModule,FormatterConfig} -

The formatter which the handler can use for converting - the log event term to a printable string.

-

See Formatters for more - information.

-

Default - is {logger_formatter,DefaultFormatterConfig}, see +

Specifies a formatter that the handler can use for + converting the log event term to a printable string.

+ + FormatterModule = module() + FormatterConfig = + + logger:formatter_config() + +

The formatter information is specified when adding the + handler. The formatter configuration can be changed during + runtime + with + logger:update_formatter_config/2,3, + or the complete formatter information can be overwritten + with, for + instance, + logger:set_handler_config/3.

+

See + section Formatters + for more detailed information.

+

Defaults + to {logger_formatter,DefaultFormatterConfig}. See the - logger_formatter(3) - manual for information about this formatter and its - default configuration.

+ logger_formatter(3) manual page for + information about this formatter and its default + configuration.

- HandlerConfig, atom() = term() - -

Any keys not listed above are considered to be handler - specific configuration. The configuration of the Kernel - handlers can be found in + config = term() + +

Handler specific configuration, that is, configuration + data related to a specific handler implementation.

+

The configuration for the built-in handlers is described + in the logger_std_h(3) and logger_disk_log_h(3) manual pages.

-
+

Notice that level and filters are obeyed by Logger itself before forwarding the log events to each - handler, while formatter and all handle specific + handler, while formatter and all handler specific options are left to the handler implementation.

-

All Logger's built-in handlers will call the given formatter - before printing.

+
+ +
+ + Kernel Configuration Parameters + +

The following Kernel configuration parameters apply to + Logger:

+ + logger = [Config] + +

Specifies the configuration + for Logger, except the + primary log level, which is specified + with logger_level, + and the compatibility + with SASL Error + Logging, which is specified + with + logger_sasl_compatible.

+

With this parameter, you can modify or disable the default + handler, add custom handlers and primary logger filters, and + set log levels per module.

+

Config is any (zero or more) of the following:

+ + {handler, default, undefined} + +

Disables the default handler. This allows another + application to add its own default handler.

+

Only one entry of this type is allowed.

+
+ {handler, HandlerId, Module, HandlerConfig} + +

If HandlerId is default, then this entry + modifies the default handler, equivalent to calling

+

+		logger:set_handler_config(default, Module, HandlerConfig)
+	      
+

For all other values of HandlerId, this entry + adds a new handler, equivalent to calling

+

+		logger:add_handler(HandlerId, Module, HandlerConfig)
+	    
+

Multiple entries of this type are allowed.

+ {filters, FilterDefault, [Filter]} + +

Adds the specified primary filters.

+ + FilterDefault = log | stop + Filter = {FilterId, {FilterFun, FilterConfig}} + +

Equivalent to calling

+

+		logger:add_primary_filter(FilterId, {FilterFun, FilterConfig})
+	    
+

for each Filter.

+

FilterDefault specifies the behaviour if all + primary filters return ignore, see + section Filters.

+

Only one entry of this type is allowed.

+
+ {module_level, Level, [Module]} + +

Sets module log level for the given modules. Equivalent + to calling

+

+		logger:set_module_level(Module, Level)
+

for each Module.

+

Multiple entries of this type are allowed.

+
+
+

See + section Configuration + Examples for examples using the logger + parameter for system configuration.

+
+ + logger_level = Level + +

Specifies the primary log level. See + the kernel(6) + manual page for more information about this parameter.

+
+ + logger_sasl_compatible = true | false + +

Specifies Logger's compatibility + with SASL Error + Logging. See + the + kernel(6) manual page for more + information about this parameter.

+
+
+
+ +
+ + Configuration Examples +

The value of the Kernel configuration parameter logger + is a list of tuples. It is possible to write the term on the + command line when starting an erlang node, but as the term + grows, a better approach is to use the system configuration + file. See + the config(4) manual + page for more information about this file.

+

Each of the following examples shows a simple system + configuration file that configures Logger according to the + description.

+

Modify the default handler to print to a file instead of + standard_io:

+ +[{kernel, + [{logger, + [{handler, default, logger_std_h, % {handler, HandlerId, Module, + #{config => #{type => {file,"log/erlang.log"}}}} % Config} + ]}]}]. + +

Modify the default handler to print each log event as a + single line:

+ +[{kernel, + [{logger, + [{handler, default, logger_std_h, + #{formatter => {logger_formatter, #{single_line => true}}}} + ]}]}]. + +

Modify the default handler to print the pid of the logging + process for each log event:

+ +[{kernel, + [{logger, + [{handler, default, logger_std_h, + #{formatter => {logger_formatter, + #{template => [time," ",pid," ",msg,"\n"]}}}} + ]}]}]. + +

Modify the default handler to only print errors and more + severe log events to "log/erlang.log", and add another handler + to print all log events to "log/debug.log".

+ +[{kernel, + [{logger, + [{handler, default, logger_std_h, + #{level => error, + config => #{type => {file, "log/erlang.log"}}}}, + {handler, info, logger_std_h, + #{level => debug, + config => #{type => {file, "log/debug.log"}}}} + ]}]}]. +
@@ -687,8 +830,9 @@ logger:debug(#{got => connection_request, id => Id, state => State},

To get log events on the same format as produced by error_logger_tty_h and error_logger_file_h, use the default formatter, logger_formatter, with - configuration parameter legacy_header => true. This is - also the default.

+ configuration parameter legacy_header set + to true. This is the default configuration of + the default handler started by Kernel.

Default Format of Log Events from OTP @@ -700,12 +844,11 @@ logger:debug(#{got => connection_request, id => Id, state => State},

By SASL reports we mean supervisor reports, crash reports and progress reports.

-

In earlier releases, these reports were only logged when - the SASL application was running, and they were printed - trough specific event handlers - named sasl_report_tty_h +

Prior to Erlang/OTP 21.0, these reports were only logged + when the SASL application was running, and they were printed + trough SASL's own event handlers sasl_report_tty_h and sasl_report_file_h.

-

The destination of these log events were configured by +

The destination of these log events was configured by SASL configuration parameters.

Due to the specific event handlers, the output format @@ -716,17 +859,20 @@ logger:debug(#{got => connection_request, id => Id, state => State}, Supervisor reports, crash reports, and progress reports are no longer connected to the SASL application. - Supervisor reports and crash reports are logged by - default. - Progress reports are not logged by default, but can be - enabled with the Kernel configuration - parameter - logger_progress_reports. + Supervisor reports and crash reports are issued + as error level log events, and are logged through + the default handler started by Kernel. + Progress reports are issued as info level log + events, and since the default primary log level + is notice, these are not logged by default. To + enable printing of progress reports, set + the primary log + level to info. The output format is the same for all log events. -

If the old behaviour is preferred, the Kernel configuation - parameter +

If the old behaviour is preferred, the Kernel configuration + parameter logger_sasl_compatible can be set to true. The SASL @@ -734,11 +880,10 @@ logger:debug(#{got => connection_request, id => Id, state => State}, before, and the SASL reports will only be printed if the SASL application is running, through a second log handler named sasl.

-

All SASL reports have a metadata - field domain => [beam,erlang,otp,sasl], which can be - used, for example, by filters to stop or allow the - log events.

-

See the SASL User's +

All SASL reports have a metadata field domain which + is set to [otp,sasl]. This field can be + used by filters to stop or allow the log events.

+

See section SASL User's Guide for more information about the old SASL error logging functionality.

@@ -749,21 +894,22 @@ logger:debug(#{got => connection_request, id => Id, state => State}, error_logger:add_report_handler/1,2. -

This will automatically start the error_logger - event manager, and add error_logger as a - handler to logger, with configuration

+

This automatically starts the error logger event manager, + and adds error_logger as a handler to Logger, with + the following configuration:

#{level => info, filter_default => log, filters => []}. -

Notice that this handler will ignore events that do not - originate from the error_logger API, or from within - OTP. This means that if your code uses the Logger API for - logging, then your log events will be discarded by this - handler.

-

Also notice that error_logger is not overload - protected.

+ +

This handler ignores events that do not originate from + the error_logger API, or from within OTP. This + means that if your code uses the Logger API for logging, + then your log events will be discarded by this + handler.

+

The handler is not overload protected.

+
@@ -771,100 +917,108 @@ error_logger:add_report_handler/1,2.
Error Handling -

Log data is expected to be either a format string and - arguments, a string - ( - unicode:chardata()), or a report (map or - key-value list) which can be converted to a format string and - arguments by the handler. If a report is given, a default report - callback can be included in the log event's metadata. The - handler can use this callback for converting the report to a - format string and arguments. If the format obtained by the - provided callback is not desired, or if there is no provided - callback, the handler must do a custom conversion.

-

Logger does, to a certain extent, check its input data - before forwarding a log event to the handlers, but it does not - evaluate conversion funs or check the validity of format strings - and arguments. This means that any filter or handler must be - careful when formatting the data of a log event, making sure - that it does not crash due to bad input data or faulty - callbacks.

+

Logger does, to a certain extent, check its input data before + forwarding a log event to filters and handlers. It does, + however, not evaluate report callbacks, or check the validity of + format strings and arguments. This means that all filters and + handlers must be careful when formatting the data of a log + event, making sure that it does not crash due to bad input data + or faulty callbacks.

If a filter or handler still crashes, Logger will remove the filter or handler in question from the configuration, and print a short error message to the terminal. A debug event containing - the crash reason and other details is also issued, and can be - seen if a handler logging debug events is installed.

+ the crash reason and other details is also issued.

+

See section Log + Message for more information about report callbacks + and valid forms of log messages.

- Example: add a handler to log debug events to file + Example: Add a handler to log debug events to file

When starting an Erlang node, the default behaviour is that all - log events with level info and above are logged to the - terminal. In order to also log debug events, you can either - change the global log level to debug or add a separate - handler to take care of this. In this example we will add a new - handler which prints the debug events to a separate file.

-

First, we add an instance of logger_std_h with - type {file,File}, and we set the handler's level - to debug:

+ log events on level info or more severe, are logged to the + terminal via the default handler. To also log debug events, you + can either change the primary log level to debug:

-1> Config = #{level => debug, logger_std_h => #{type => {file,"./debug.log"}}}.
-#{logger_std_h => #{type => {file,"./debug.log"}},
-  level => debug}
-2> logger:add_handler(debug_handler,logger_std_h,Config).
+1> logger:set_primary_config(level, debug).
 ok
-

By default, the handler receives all events - (filter_default=log, see - section Filters for more - details), so we need to add a filter to stop all non-debug - events. The built-in - filter - logger_filters:level/2 - is used for this:

+

or set the level for one or a few modules only:

-3> logger:add_handler_filter(debug_handler,stop_non_debug,
-                             {fun logger_filters:level/2,{stop,neq,debug}}).
+2> logger:set_module_level(mymodule, debug).
 ok
-

And finally, we need to make sure that Logger itself allows - debug events. This can either be done by setting the global - log level:

+

This allows debug events to pass through to the default handler, + and be printed to the terminal as well. If there are many debug + events, it can be useful to print these to a file instead.

+

First, set the log level of the default handler to info, + preventing it from printing debug events to the terminal:

-4> logger:set_logger_config(level,debug).
+3> logger:set_handler_config(default, level, info).
 ok
-

Or by allowing debug events from one or a few modules only:

+

Then, add a new handler which prints to file. You can use the + handler + module logger_std_h, + and specify type {file,File}. The default handler level + is all, so you don't need to specify that:

+
+4> Config = #{config => #{type => {file,"./debug.log"}}}.
+#{config => #{type => {file,"./debug.log"}}}
+5> logger:add_handler(debugger, logger_std_h, Config).
+ok
+

Since filter_default defaults to log, this + handler now receives all log events. If you want debug events + only in the file, you must add a filter to stop all non-debug + events. The built-in + filter + logger_filters:level/2 + can do this:

-5> logger:set_module_level(mymodule,debug).
+6> logger:add_handler_filter(debugger, stop_non_debug,
+                             {fun logger_filters:level/2, {stop, neq, debug}}).
 ok
+

See section Filters for + more information about the filters and the filter_default + configuration parameter.

- Example: implement a handler -

The only requirement that a handler MUST fulfill is to export - the following function:

- log(logger:log_event(),logger:config()) -> ok -

It can optionally also implement the following callbacks:

- -adding_handler(logger:config()) -> {ok,logger:config()} | {error,term()} -removing_handler(logger:config()) -> ok -changing_config(logger:config(),logger:config()) -> {ok,logger:config()} | {error,term()} - -

When logger:add_handler(Id,Module,Config) is called, + Example: Implement a handler +

Section Handler + Callback Functions in the logger(3) manual page + describes the callback functions that can be implemented for a + Logger handler.

+

A handler callback module must export:

+ + log(Log, Config) + +

It can optionally also export some, or all, of the following:

+ + adding_handler(Config) + removing_handler(Config) + changing_config(OldConfig, NewConfig) + +

When a handler is added, by for example a call + to + logger:add_handler(Id, HModule, Config), Logger first calls HModule:adding_handler(Config). If - this function returns {ok,NewConfig}, Logger - writes NewConfig to the configuration database, and + this function returns {ok,Config1}, Logger + writes Config1 to the configuration database, and the logger:add_handler/3 call returns. After this, the handler is installed and must be ready to receive log events as calls to HModule:log/2.

A handler can be removed by calling - logger:remove_handler(Id). Logger calls + + logger:remove_handler(Id). Logger calls HModule:removing_handler(Config), and removes the handler's configuration from the configuration database.

-

When logger:set_handler_config/2,3 - or logger:update_handler_config/2 is called, Logger - calls HModule:changing_config(OldConfig,NewConfig). If - this function returns {ok,NewConfig}, Logger - writes NewConfig to the configuration database.

+

When + logger:set_handler_config/2,3 + or + logger:update_handler_config/2 is called, + Logger + calls HModule:changing_config(OldConfig, NewConfig). If + this function returns {ok,NewConfig1}, Logger + writes NewConfig1 to the configuration database.

A simple handler that prints to the terminal can be implemented as follows:

@@ -872,11 +1026,11 @@ changing_config(logger:config(),logger:config()) -> {ok,logger:config()} | {erro -module(myhandler). -export([log/2]). -log(LogEvent,#{formatter:={FModule,FConfig}) -> - io:put_chars(FModule:format(LogEvent,FConfig)). +log(LogEvent, #{formatter := {FModule, FConfig}) -> + io:put_chars(FModule:format(LogEvent, FConfig)). -

A simple handler which prints to file could be implemented like +

A simple handler which prints to file can be implemented like this:

-module(myhandler). @@ -884,28 +1038,29 @@ log(LogEvent,#{formatter:={FModule,FConfig}) -> -export([init/1, handle_call/3, handle_cast/2, terminate/2]). adding_handler(Config) -> - {ok,Fd} = file:open(File,[append,{encoding,utf8}]), - {ok,Config#{myhandler_fd => Fd}}. + {ok, Fd} = file:open(File, [append, {encoding, utf8}]), + {ok, Config#{myhandler_fd => Fd}}. -removing_handler(#{myhandler_fd:=Fd}) -> +removing_handler(#{myhandler_fd := Fd}) -> _ = file:close(Fd), ok. -log(LogEvent,#{myhandler_fd:=Fd,formatter:={FModule,FConfig}}) -> - io:put_chars(Fd,FModule:format(LogEvent,FConfig)). +log(LogEvent,#{myhandler_fd := Fd, formatter := {FModule, FConfig}}) -> + io:put_chars(Fd, FModule:format(LogEvent, FConfig)). -

The above handlers do not have any overload - protection, and all log events are printed directly from the - client process.

- -

For information and examples of overload protection, please - refer to - section Protecting the - Handler from Overload, and the implementation - of logger_std_h(3) - and logger_disk_log_h(3) - .

+ +

The above handlers do not have any overload + protection, and all log events are printed directly from the + client process.

+

For information and examples of overload protection, please + refer to + section Protecting the + Handler from Overload, and the implementation + of logger_std_h + and logger_disk_log_h + .

+

Below is a simpler example of a handler which logs through one single process.

@@ -915,33 +1070,33 @@ log(LogEvent,#{myhandler_fd:=Fd,formatter:={FModule,FConfig}}) -> -export([init/1, handle_call/3, handle_cast/2, terminate/2]). adding_handler(Config) -> - {ok,Pid} = gen_server:start(?MODULE,Config), - {ok,Config#{myhandler_pid => Pid}}. + {ok, Pid} = gen_server:start(?MODULE, Config), + {ok, Config#{myhandler_pid => Pid}}. -removing_handler(#{myhandler_pid:=Pid}) -> +removing_handler(#{myhandler_pid := Pid}) -> gen_server:stop(Pid). -log(LogEvent,#{myhandler_pid:=Pid} = Config) -> - gen_server:cast(Pid,{log,LogEvent,Config}). +log(LogEvent,#{myhandler_pid := Pid} = Config) -> + gen_server:cast(Pid, {log, LogEvent, Config}). -init(#{myhandler_file:=File}) -> - {ok,Fd} = file:open(File,[append,{encoding,utf8}]), - {ok,#{file => File, fd => Fd}}. +init(#{myhandler_file := File}) -> + {ok, Fd} = file:open(File, [append, {encoding, utf8}]), + {ok, #{file => File, fd => Fd}}. -handle_call(_,_,State) -> - {reply,{error,bad_request},State}. +handle_call(_, _, State) -> + {reply, {error, bad_request}, State}. -handle_cast({log,LogEvent,Config},#{fd:=Fd} = State) -> - do_log(Fd,LogEvent,Config), - {noreply,State}. +handle_cast({log, LogEvent, Config}, #{fd := Fd} = State) -> + do_log(Fd, LogEvent, Config), + {noreply, State}. -terminate(Reason,#{fd:=Fd}) -> +terminate(Reason, #{fd := Fd}) -> _ = file:close(Fd), ok. -do_log(Fd,LogEvent,#{formatter:={FModule,FConfig}}) -> - String = FModule:format(LogEvent,FConfig), - io:put_chars(Fd,String). +do_log(Fd, LogEvent, #{formatter := {FModule, FConfig}}) -> + String = FModule:format(LogEvent, FConfig), + io:put_chars(Fd, String).
@@ -985,7 +1140,7 @@ do_log(Fd,LogEvent,#{formatter:={FModule,FConfig}}) -> level below the toggle_sync_qlen threshold, asynchronous operation is resumed. The switch from asynchronous to synchronous mode will force the logging tempo of few busy senders to slow down, - but can not protect the handler sufficiently in situations of many + but cannot protect the handler sufficiently in situations of many concurrent senders.

drop_new_reqs_qlen @@ -1044,11 +1199,11 @@ do_log(Fd,LogEvent,#{formatter:={FModule,FConfig}}) ->

A configuration example:

logger:add_handler(my_standard_h, logger_std_h, - #{logger_std_h => - #{type => {file,"./system_info.log"}, - toggle_sync_qlen => 100, - drop_new_reqs_qlen => 1000, - flush_reqs_qlen => 2000}}). + #{config => + #{type => {file,"./system_info.log"}, + toggle_sync_qlen => 100, + drop_new_reqs_qlen => 1000, + flush_reqs_qlen => 2000}}).
@@ -1086,10 +1241,10 @@ logger:add_handler(my_standard_h, logger_std_h, logger:add_handler(my_disk_log_h, logger_disk_log_h, #{disk_log_opts => - #{file => "./my_disk_log"}, - logger_disk_log_h => - #{burst_limit_size => 10, - burst_window_time => 500}}). + #{file => "./my_disk_log"}, + config => + #{burst_limit_size => 10, + burst_window_time => 500}}).
diff --git a/lib/kernel/doc/src/logger_disk_log_h.xml b/lib/kernel/doc/src/logger_disk_log_h.xml index 20b49b8ca0..63c29cb010 100644 --- a/lib/kernel/doc/src/logger_disk_log_h.xml +++ b/lib/kernel/doc/src/logger_disk_log_h.xml @@ -44,7 +44,7 @@ the handler configuration.

The default standard handler, logger_std_h, can be - replaced by a disk_log handler at startup of the Kernel application. + replaced by a disk_log handler at start up of the Kernel application. See an example of this below.

The handler has an overload protection mechanism that will keep the handler process and the Kernel application alive during a high load of log @@ -60,7 +60,7 @@ , as well as handler specific parameters.

The settings for the disk_log log file should be specified with the key disk_log_opts. These settings are a subset of the disk_log - datatype + data type dlog_option().

Parameters in the disk_log_opts map:

@@ -81,7 +81,7 @@ log.

Specific configuration for the handler (represented as a sub map) - is specified with the key logger_disk_log_h. It may contain the + is specified with the key config. It may contain the following parameter:

filesync_repeat_interval @@ -93,7 +93,7 @@ since the last sync. The default value is 5000 milliseconds. If no_repeat is set as value, the repeated sync operation is disabled. The user can also call the - disk_log_sync/1 + sync/1 function to perform a disk_log sync.

There are a number of other configuration parameters available, that are @@ -117,7 +117,7 @@ logger:add_handler(my_disk_log_h, logger_disk_log_h, type => wrap, max_no_files => 4, max_no_bytes => 10000}, - logger_disk_log_h => + config => #{filesync_repeat_interval => 1000}}).

In order to use the disk_log handler instead of the default standard @@ -125,14 +125,14 @@ logger:add_handler(my_disk_log_h, logger_disk_log_h, use disk_log. Example:

erl -kernel logger '[{handler,default,logger_disk_log_h, - #{ disk_log_opts => #{ file => "./system_disk_log"}}}]' + #{disk_log_opts => #{file => "./system_disk_log"}}}]' - + Writes buffered data to disk.

Write buffered data to disk.

@@ -143,9 +143,9 @@ erl -kernel logger '[{handler,default,logger_disk_log_h,
See Also -

logger(3)

-

logger_std_h(3)

-

disk_log(3)

+

logger(3), + logger_std_h(3), + disk_log(3)

diff --git a/lib/kernel/doc/src/logger_filters.xml b/lib/kernel/doc/src/logger_filters.xml index f92181ea3f..90f1fcc270 100644 --- a/lib/kernel/doc/src/logger_filters.xml +++ b/lib/kernel/doc/src/logger_filters.xml @@ -36,15 +36,15 @@ Filters to use with Logger. -

All functions exported from this module can be used as logger +

All functions exported from this module can be used as primary or handler - filters. See - logger:add_logger_filter/2 + filters. See + logger:add_primary_filter/2 and logger:add_handler_filter/3 for more information about how filters are added.

-

Filters are removed with - logger:remove_logger_filter/1 +

Filters are removed with + logger:remove_primary_filter/1 and logger:remove_handler_filter/2.

@@ -64,18 +64,18 @@

A domain field must be a list of atoms, creating smaller and more specialized domains as the list grows longer. The - biggest domain is [], which comprices all - possible domains.

+ greatest domain is [], which comprises all possible + domains.

For example, consider the following domains:

-D1 = [beam,erlang,otp]
-D2 = [beam,erlang,otp,sasl]
+D1 = [otp] +D2 = [otp, sasl] -

D1 is the biggest of the two, and is said to be a +

D1 is the greatest of the two, and is said to be a super-domain of D2. D2 is a sub-domain D1. Both D1 and D2 are - sub-domains of []

+ sub-domains of [].

The above domains are used for logs originating from Erlang/OTP. D1 specifies that the log event comes from @@ -86,50 +86,50 @@ D2 = [beam,erlang,otp,sasl]

The Extra parameter to the domain/2 function is specified when adding the - filter via - logger:add_logger_filter/2 + filter via + logger:add_primary_filter/2 or logger:add_handler_filter/3.

-

The filter compares the value of the domain field - in the log event's metadata (Domain) - to MatchDomain as follows:

+

The filter compares the value of the domain field in + the log event's metadata (Domain) against + MatchDomain. The filter matches if the + value of Compare is:

- Compare = sub + sub -

The filter matches if Domain is equal to or - a sub-domain of MatchDomain, that is, - if MatchDomain is a prefix of Domain.

+

and Domain is equal to or a sub-domain + of MatchDomain, that is, if MatchDomain is + a prefix of Domain.

- Compare = super + super -

The filter matches if Domain is equal to or a - super-domain of MatchDomain, that is, - if Domain is a prefix of MatchDomain.

+

and Domain is equal to or a super-domain + of MatchDomain, that is, if Domain is a + prefix of MatchDomain.

- Compare = equal + equal -

The filter matches if Domain is equal - to MatchDomain.

+

and Domain is equal to MatchDomain.

- Compare = not_equal + not_equal -

The filter matches if Domain is not equal - to MatchDomain, or if there is no domain field in - metadata.

+

and Domain differs from MatchDomain, or + if there is no domain field in metadata.

- Compare = undefined -

The filter matches if there is no domain field in - metadata. In this case MatchDomain - must be set to [].

+ undefined + +

and there is no domain field in metadata. In this + case MatchDomain must be set + to [].

-

If the filter matches and Action = log, - the log event is allowed. If the filter matches - and Action = stop, the log event is - stopped.

+

If the filter matches and Action is + log, the log event is allowed. If the filter matches + and Action is stop, the log event + is stopped.

If the filter does not match, it returns ignore, meaning that other filters, or the value of the @@ -137,16 +137,16 @@ D2 = [beam,erlang,otp,sasl] event is allowed or not.

Log events that do not contain any domain field, match only - when Compare = undefined - or Compare = not_equal.

+ when Compare is equal + to undefined or not_equal.

-

Example: stop all events with - domain [beam,erlang,otp,sasl|_]

+

Example: stop all events with domain [otp, + sasl | _]

-logger:set_handler_config(h1,filter_default,log). % this is the default -Filter = {fun logger_filters:domain/2,{stop,sub,[beam,erlang,otp,sasl]}}. -logger:add_handler_filter(h1,no_sasl,Filter). +logger:set_handler_config(h1, filter_default, log). % this is the default +Filter = {fun logger_filters:domain/2, {stop, sub, [otp, sasl]}}. +logger:add_handler_filter(h1, no_sasl, Filter). ok
@@ -157,34 +157,44 @@ ok

This filter provides a way of filtering log events based on the log level. It matches log events by comparing the - log level with a predefined MatchLevel

+ log level with a specified MatchLevel

The Extra parameter is specified when adding the filter - via - logger:add_logger_filter/2 + via + logger:add_primary_filter/2 or logger:add_handler_filter/3.

The filter compares the value of the event's log level (Level) to MatchLevel by calling - logger:compare_levels(Level,MatchLevel) -> CmpRet. It - matches the event if:

- - - CmpRet = eq and Operator = - eq | lteq | gteq - CmpRet = lt and Operator = - lt | lteq | neq - CmpRet = gt and Operator = - gt | gteq | neq - - -

If the filter matches and Action = - log, the log event is allowed. If the filter matches - and Action = stop, the log event is - stopped.

+ logger:compare_levels(Level, MatchLevel). + The filter matches if the value + of Operator is:

+ + + neq +

and the compare function returns lt + or gt.

+ eq +

and the compare function returns eq.

+ lt +

and the compare function returns lt.

+ gt +

and the compare function returns gt.

+ lteq +

and the compare function returns lt + or eq.

+ gteq +

and the compare function returns gt + or eq.

+
+ +

If the filter matches and Action is + log, the log event is allowed. If the filter + matches and Action is stop, the + log event is stopped.

If the filter does not match, it returns ignore, meaning that other filters, or the value of the @@ -194,9 +204,9 @@ ok

Example: only allow debug level log events

-logger:set_handler_config(h1,filter_default,stop). -Filter = {fun logger_filters:level/2,{log,eq,debug}}. -logger:add_handler_filter(h1,debug_only,Filter). +logger:set_handler_config(h1, filter_default, stop). +Filter = {fun logger_filters:level/2, {log, eq, debug}}. +logger:add_handler_filter(h1, debug_only, Filter). ok
@@ -208,9 +218,9 @@ ok

This filter matches all progress reports from supervisor and application_controller.

-

If Extra = log, the progress reports - are allowed. If Extra = stop, the - progress reports are stopped.

+

If Extra is log, the progress + reports are allowed. If Extra + is stop, the progress reports are stopped.

The filter returns ignore for all other log events.

@@ -223,9 +233,9 @@ ok

This filter matches all events originating from a process that has its group leader on a remote node.

-

If Extra = log, the matching events - are allowed. If Extra = stop, the - matching events are stopped.

+

If Extra is log, the matching + events are allowed. If Extra + is stop, the matching events are stopped.

The filter returns ignore for all other log events.

@@ -233,6 +243,12 @@ ok +
+ See Also +

+ logger(3) +

+
diff --git a/lib/kernel/doc/src/logger_formatter.xml b/lib/kernel/doc/src/logger_formatter.xml index 02f89b26be..59f5dbe367 100644 --- a/lib/kernel/doc/src/logger_formatter.xml +++ b/lib/kernel/doc/src/logger_formatter.xml @@ -36,12 +36,15 @@ Default formatter for Logger. -

Each log handler has a configured formatter specified as a +

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

+ ) 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.

@@ -55,7 +58,8 @@ map, and the following keys can be set as configuration parameters:

- chars_limit = pos_integer() | unlimited + + chars_limit = integer() > 0 | unlimited

A positive integer representing the value of the option with the same name to be used when calling @@ -65,14 +69,8 @@ for each log event. Notice that this is a soft limit. For a hard truncation limit, see option max_size.

Defaults to 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 + depth = integer() > 0 | unlimited

A positive integer representing the maximum depth to which terms shall be printed by this formatter. Format @@ -83,26 +81,23 @@ io:format/2,3 in STDLIB.

Defaults to 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.

-
legacy_header = boolean()

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 + the + old error_logger + event handlers. It can be included in the log event by + adding the list [logger_formatter,header] to the template. See the description of the template() type for more information.

Defaults to false.

- max_size = pos_integer() | unlimited + + max_size = integer() > 0 | unlimited

A positive integer representing the absolute maximum size a string returned from this formatter can have. If the @@ -110,12 +105,12 @@ by chars_limit or depth, it is truncated.

Defaults to unlimited.

- report_cb = fun((logger:report()) -> {io:format(),[term()]}) + 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 + metadata for the log event. If no report callback exists in metadata, logger_formatter will use logger:format_report/1 as default @@ -131,12 +126,14 @@ 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 + replaced with ", ", and white spaces following + directly after newlines are removed. Notice that newlines added by the template parameter are not replaced.

Defaults to true.

- template = template() + + template = template() +

The template describes how the formatted string is composed by combining different data values from the log @@ -183,32 +180,43 @@ + + + +

+ + -

The template is a list of atoms, tuples and strings. The +

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 tuples are interpreted as + respectively. Other atoms or atom lists are interpreted as placeholders for metadata, where atoms are expected to match - top level keys, and tuples represent paths to sub keys when + top level keys, and atom lists represent paths to sub keys when the metadata is a nested map. For example the - tuple {key1,key2} is replaced by the value of + 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, - ...} + +#{key1 => #{key2 => my_value, + ...} ...} -

Strings in the template are printed literally.

-

The default template differs depending on the values - of legacy_header - and single_line:

+

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 @@ -216,13 +224,13 @@

The log event used in the examples is:

-?LOG_ERROR("name: ~p~nexit_reason: ~p",[my_name,"It crashed"]) +?LOG_ERROR("name: ~p~nexit_reason: ~p", [my_name, "It crashed"])
- legacy_header=true, single_line=false + legacy_header = true, single_line = false

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

+ template: [[logger_formatter,header],"\n",msg,"\n"]

Example log entry:

@@ -231,15 +239,16 @@ name: my_name exit_reason: "It crashed"

Notice that all eight levels can 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.

+ not only ERROR, WARNING or INFO as + error_logger + produces. And microseconds are added at the end of the + timestamp.

- legacy_header=true, single_line=true + legacy_header = true, single_line = true

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

+ template: [[logger_formatter,header],"\n",msg,"\n"]

Notice that the template is here the same as for single_line=false, but the resulting log entry @@ -250,7 +259,7 @@ exit_reason: "It crashed" name: my_name, exit_reason: "It crashed" - legacy_header=false, single_line=true + legacy_header = false, single_line = true

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

@@ -259,7 +268,7 @@ name: my_name, exit_reason: "It crashed" 2018-05-17T18:31:31.152864+02:00 error: name: my_name, exit_reason: "It crashed"
- legacy_header=false, single_line=false + legacy_header = false, single_line = false

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

@@ -279,10 +288,21 @@ exit_reason: "It crashed" Validates the given formatter configuration. -

This callback function is called by Logger when the - formatter configuration for a handler is set or modified. It +

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:

+ + + logger:add_handler/3 + + logger:set_handler_config/2,3 + + logger:updata_handler_config/2 + + logger:update_formatter_config/2 +
@@ -293,22 +313,38 @@ exit_reason: "It crashed" 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. + {Format,Args} by calling the report callback. See + section Log + Message in the Kernel User's Guide for more + information about report callbacks and valid forms of log + messages.
+ The message size is limited according to the values of + configuration parameters + chars_limit + and depth. The full log entry is composed according to - the template. + the template.
If the final string is too long, it is truncated according to the value of configuration - parameter max_size. + parameter max_size. +
+ See Also +

+ calendar(3), + error_logger(3), + io(3), + io_lib(3), + logger(3), + maps(3), + sasl(6), + unicode(3) +

+
diff --git a/lib/kernel/doc/src/logger_std_h.xml b/lib/kernel/doc/src/logger_std_h.xml index a4f2848037..89e11389c5 100644 --- a/lib/kernel/doc/src/logger_std_h.xml +++ b/lib/kernel/doc/src/logger_std_h.xml @@ -54,7 +54,7 @@ general configuration parameters, as documented in the User's Guide , as well as handler specific parameters. The specific parameters - are stored in a sub map with the key logger_std_h. The following + are stored in a sub map with the key config. The following keys and values may be specified:

type @@ -78,7 +78,7 @@ If no_repeat is set as value, the repeated file sync operation is disabled, and it will be the operating system settings that determine how quickly or slowly data gets written to disk. The user can also call - the filesync/1 + the sync/1 function to perform a file sync.

There are a number of other configuration parameters available, that are @@ -99,26 +99,26 @@ logger:add_handler(my_standard_h, logger_std_h, #{level => info, filter_default => log, - logger_std_h => - #{type => {file,"./system_info.log"}, - filesync_repeat_interval => 1000}}). + config => + #{type => {file,"./system_info.log"}, + filesync_repeat_interval => 1000}}).

In order to configure the default handler (that starts initially with the Kernel application) to log to file instead of standard_io, change the Kernel default logger to use a file. Example:

erl -kernel logger '[{handler,default,logger_std_h, - #{ logger_std_h => #{ type => {file,"./log.log"}}}}]' + #{config => #{type => {file,"./log.log"}}}}]'

An example of how to replace the standard handler with a disk_log handler - at startup can be found in the manual of + at start up can be found in the manual of logger_disk_log_h.

- + Writes buffered data to disk.

Write buffered data to disk.

@@ -129,8 +129,9 @@ erl -kernel logger '[{handler,default,logger_std_h,
See Also -

logger(3)

-

logger_disk_log_h(3)

+

logger(3), + + logger_disk_log_h(3)

diff --git a/lib/kernel/doc/src/part.xml b/lib/kernel/doc/src/part.xml index 68eb4530e2..fa7e92835f 100644 --- a/lib/kernel/doc/src/part.xml +++ b/lib/kernel/doc/src/part.xml @@ -4,7 +4,7 @@
- 19962017 + 2018 Ericsson AB. All Rights Reserved. @@ -22,17 +22,14 @@ - Logger User's Guide + Kernel User's Guide OTP Team - 2017-12-01 - 0.1 + 2018-06-06 part.xml
-

The System Architecture Support Libraries SASL application - provides support for alarm handling, release handling, and - related functions.

+

-- cgit v1.2.3