From a9a6b803a60793d42a74e0f1693a7594dffb6bc3 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Thu, 17 May 2018 18:19:57 +0200 Subject: Improve documentation of logger and error_logger --- lib/kernel/doc/src/error_logger.xml | 48 +++--- lib/kernel/doc/src/introduction_chapter.xml | 1 - lib/kernel/doc/src/kernel_app.xml | 11 +- lib/kernel/doc/src/logger.xml | 184 ++++++++++++++--------- lib/kernel/doc/src/logger_chapter.xml | 222 ++++++++++++++++------------ lib/kernel/doc/src/logger_disk_log_h.xml | 22 ++- lib/kernel/doc/src/logger_formatter.xml | 40 +++-- lib/kernel/doc/src/logger_std_h.xml | 19 ++- 8 files changed, 320 insertions(+), 227 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 c9fe9484e4..e91fc734a4 100644 --- a/lib/kernel/doc/src/error_logger.xml +++ b/lib/kernel/doc/src/error_logger.xml @@ -36,41 +36,31 @@

In OTP-21, a new API for logging was added to Erlang/OTP. The old error_logger module can still be used by legacy code, but new code should use the new API instead.

+

error_logger is no longer started by default, but is + automatically started when an event handler is added + with error_logger:add_report_handler/1,2. The error_logger + module is then also added as a handler to the new logger.

See logger(3) and the Logging chapter - in the user's guide for more information.

+ in the User's Guide for more information.

The Erlang error logger is an event manager (see OTP Design Principles and gen_event(3)), - registered as error_logger. Errors, warnings, and info events - are sent to the error logger from the Erlang runtime system and - the different Erlang/OTP applications. The events are, by default, - logged to the terminal. Notice that an event from a process P is - logged at the node of the group leader of P. This means - that log output is directed to the node from which a process was - created, which not necessarily is the same node as where it is - executing.

-

Initially, error_logger has only a primitive event - handler, which buffers and prints the raw event messages. During - system startup, the Kernel application replaces this with a - standard event handler, by default one that writes - nicely formatted output to the terminal. Kernel can also be - configured so that events are logged to a file instead, or not logged at all, - see kernel(6).

-

Also the SASL application, if started, adds its own event - handler, which by default writes supervisor, crash, and progress - reports to the terminal. See - sasl(6).

-

It is recommended that user-defined applications report - errors through the error logger to get uniform reports. - User-defined event handlers can be added to handle application-specific - events, see - add_report_handler/1,2. - Also, a useful event handler is provided in STDLIB for multi-file - logging of events, see - log_mf_h(3).

+ registered as error_logger.

+

Error logger is no longer started by default, but is + automatically started when an event handler is added + with + add_report_handler/1,2. The error_logger + module is then also added as a handler to the new logger, + causing log events to be forwarded from logger to error logger, + and consequently to all installed error logger event + handlers.

+

User-defined event handlers can be added to handle application-specific + events.

+

Existing event handlers provided by STDLIB and SASL are still + available, but are no longer used by OTP.

Warning events were introduced in Erlang/OTP R9C and are enabled by default as from Erlang/OTP 18.0. To retain backwards compatibility with existing user-defined event handlers, the warning events can be @@ -191,7 +181,7 @@ ok

The error_logger_format_depth variable is deprecated since - the Logger API was + the logging API was introduced in OTP-21. The variable, and this function, are kept for backwards compatibility since they still might be used by legacy report handlers.

diff --git a/lib/kernel/doc/src/introduction_chapter.xml b/lib/kernel/doc/src/introduction_chapter.xml index 6e6990ddda..2eadc70abf 100644 --- a/lib/kernel/doc/src/introduction_chapter.xml +++ b/lib/kernel/doc/src/introduction_chapter.xml @@ -46,7 +46,6 @@ Start, stop, supervision, configuration, and distribution of applications Code loading Logging - Error logging Global name service Supervision of Erlang/OTP Communication with sockets diff --git a/lib/kernel/doc/src/kernel_app.xml b/lib/kernel/doc/src/kernel_app.xml index 7cd05dab14..5bc423afb6 100644 --- a/lib/kernel/doc/src/kernel_app.xml +++ b/lib/kernel/doc/src/kernel_app.xml @@ -42,7 +42,6 @@ Start, stop, supervision, configuration, and distribution of applications Code loading Logging - Error logging Global name service Supervision of Erlang/OTP Communication with sockets @@ -194,9 +193,9 @@ If the SASL application is started, these log events will be sent to a second handler instance named sasl_h, according to values of the SASL - environment variables sasl_error_logger + configuration parameter sasl_error_logger and sasl_errlog_type, see - SASL(6) + sasl(6)

The default value is false.

See chapter Backwards @@ -271,7 +270,7 @@ inet_parse_error_log = silent

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

@@ -486,7 +485,7 @@ MaxT = TickTime + TickTime / 4 old error_logger event manager, and event handlers running on this manager, will still work, but they are not used by default.

-

The following application environment variables can still be +

The following application configuration parameters can still be set, but they will only be used if the corresponding new logger variables are not set.

@@ -519,12 +518,12 @@ erl -kernel logger '[{handler,default,logger_std_h,#{formatter=>{logger_formatte disk_log(3), erl_boot_server(3), erl_ddll(3), - error_logger(3), file(3), global(3), global_group(3), heart(3), inet(3), + logger(3), net_kernel(3), os(3), pg2(3), diff --git a/lib/kernel/doc/src/logger.xml b/lib/kernel/doc/src/logger.xml index cac9c39f2a..f7e740e90d 100644 --- a/lib/kernel/doc/src/logger.xml +++ b/lib/kernel/doc/src/logger.xml @@ -33,23 +33,51 @@ logger.xml logger - API module for the logger. + API module for logging in Erlang/OTP. + + + + +

- This module is the main logger API. It contains functions that allow - application to use a single log API and the system to manage those log - events independently. To log events the logger - macros should be used. For instance, - to log a new error log event:

+ 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 will then be sent to the configured log handlers which - by default means that it will be printed to the console. If you want +

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 - have to configure the default handler to do so. The simplest way is + must configure the default handler to do so. The simplest way is to include the following in your sys.config.

[{kernel, @@ -63,7 +91,7 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro how to use the API, see the User's Guide. - how to configure logger, + how to configure Logger, see the Configuration section in the User's Guide. the convinience macros in logger.hrl, @@ -129,8 +157,8 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro update_process_metadata/1
.

Logger merges all the metadata maps before forwarding the log event to the handlers. If the same keys occur, values - from the log call overwrites process metadata, which in turn - overwrites values set by Logger.

+ from the log call overwrite process metadata, which in turn + overwrite values set by Logger.

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

A filter which can be installed for logger or for a handler.

+

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

@@ -213,9 +242,9 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro ?LOG_DEBUG(FunOrFormat,Args[,Metadata]) -

All macros expand to a call to logger, where Level is - taken from the macro name, and location data is added. See the - description of +

All macros expand to a call to Logger, where Level is + taken from the macro name, and location data is added to the + metadata. See the description of the metadata() type for more information about the location data.

@@ -335,23 +364,26 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro - Lookup the current configuration for logger. + Look up the current configuration for the logger part + of Logger. -

Lookup the current configuration for logger.

+

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

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

Lookup the current configuration for the given handler.

+

Look up the current configuration for the given handler.

- Get all logger configurations + Get all Logger configurations

Same as logger:i(term)

@@ -361,28 +393,28 @@ logger:error("error happened because: ~p",[Reason]). %% Without macro - Get all logger configurations + Get all Logger configurations -

Display or return all current logger configuration.

+

Display or return all current Logger configurations.

Action = string -

Return the pretty printed current logger configuration +

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 inbetween releases. For a +

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

+ logger:get_logger_config/0.

+

The same as calling logger:i().

Action = print -

Pretty print all the current logger configuration to +

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

logger:i(print). Current logger configuration: @@ -423,9 +455,9 @@ Current logger configuration: - Add a filter to the logger. + Add a filter to the logger part of Logger. -

Add a filter to the logger.

+

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.

@@ -436,8 +468,8 @@ Current logger configuration:

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 the - logger, where handler filters are applied.

+ log event is forwarded to the handler part of Logger, + where handler filters are applied.

stop @@ -449,9 +481,9 @@ Current logger configuration:

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 specifies if the - log event shall be discarded or forwarded to the handler - part.

+ configuration parameter for the logger part specifies if + the log event shall be discarded or forwarded to the + handler part.

See section @@ -505,10 +537,10 @@ Current logger configuration: - Remove a filter from the logger. + Remove a filter from the logger part of Logger.

Remove the filter identified - by FilterId from the logger.

+ by FilterId from the logger part of Logger.

@@ -548,21 +580,21 @@ Current logger configuration:

Set the log level for the specified Module.

The log level for a module overrides the global log level - of the logger for log event originating from the module in + 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 the - logger is info, and there is one handler, h1, - with level info and one handler, h2, with +

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 set now set +

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 the logger, use +

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

To change the log level for a handler, use @@ -572,9 +604,10 @@ Current logger configuration:

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 the logger API + 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.

+ client must explicitly add this information if module + levels shall have any effect.

@@ -590,10 +623,11 @@ Current logger configuration: - Setup logger handlers from the applications configuration parameters. + Set up log handlers from the application's + configuration parameters.

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

+ calls logger:add_handlers/1 with its contents.

@@ -602,11 +636,12 @@ Current logger configuration: Setup logger handlers. -

This function should be used by custom logger handlers to make +

This function should be used by custom Logger handlers to make configuration consistent no matter which handler the system uses. - Normal usage to to add a call to logger:add_handlers/1 - just after the processes that the handler needs are started - and pass the applications logger config as an argument. Eg.

+ Normal usage is to add a call to logger:add_handlers/1 + just after the processes that the handler needs are started, + and pass the application's logger configuration as the argument. + For example:

-behaviour(application). start(_, []) -> @@ -616,19 +651,20 @@ start(_, []) -> {ok, Pid, []}; Error -> Error end. -

This will read the logger configuration parameter from - the handler application and start the configured handlers. The contents - of the configuration use the same rules as the +

This reads the logger configuration parameter from + the my_all application and starts the configured + handlers. The contents of the configuration use the same + rules as the logger handler configuration.

-

If the handler is meant to replace the default handler the kernels - default handlers have to be disabled before the new handler is added. - A sys.config file that disables the kernel handler and adds - a custom handler could looks like this:

+

If the handler is meant to replace the default handler, the Kernel's + default handler have to be disabled before the new handler is added. + A sys.config file that disables the Kernel handler and adds + a custom handler could look like this:

[{kernel, [{logger, - %% Disable the default kernel handler + %% Disable the default Kernel handler [{handler,default,undefined}]}]}, {my_app, [{logger, @@ -640,10 +676,10 @@ start(_, []) -> - Set configuration data for the logger. + Set configuration data for the logger part of Logger. -

Set configuration data for the logger. This overwrites the - current logger configuration.

+

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 @@ -658,21 +694,25 @@ start(_, []) -> - Add or update configuration data for the logger. + Add or update configuration data for the logger part + of Logger. -

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

+

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.

- Update configuration data for the logger. + Update configuration data for the logger part of + Logger. -

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

+

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)). @@ -697,7 +737,7 @@ logger:set_logger_config(maps:merge(Old,Config)). , then do the merge before writing the new configuration back with this function.

If a key is removed compared to the current configuration, - and the key is know by Logger, the default value is used. If + and the key is known by Logger, the default value is used. If it is a custom key, then it is up to the handler implementation if the value is removed or a default value is inserted.

diff --git a/lib/kernel/doc/src/logger_chapter.xml b/lib/kernel/doc/src/logger_chapter.xml index 4232429589..21b460e72a 100644 --- a/lib/kernel/doc/src/logger_chapter.xml +++ b/lib/kernel/doc/src/logger_chapter.xml @@ -36,14 +36,14 @@ this API can be used as is, or it can be customized to suite specific needs.

It consists of two parts - the logger part and the - handler part. The logger will forward log events to one - or more handler(s).

+ handler part. The logger part forwards log events to + one or more handler(s).

Conceptual overview -

Filters can be added to the logger and to each +

Filters can be added to the logger part and to each handler. The filters decide if an event is to be forwarded or not, and they can also modify all parts of the log event.

@@ -121,10 +121,10 @@ log(Log, Config) -> ok -

A handler is called by the logger backend after filtering on - logger level and on handler level for the handler which is - about to be called. The function call is done on the client - process, and it is up to the handler implementation if other +

The handler callback is called after filtering on logger + level and on handler level for the handler in + question. The function call is done on the client process, + and it is up to the handler implementation if other processes are to be involved or not.

Multiple instances of the same handler can be @@ -134,7 +134,7 @@ Filter -

Filters can be set on the logger or on a handler. Logger +

Filters can be set on the logger part, or on a handler. Logger filters are applied first, and if passed, the handler filters for each handler are applied. The handler callback is only called if all handler filters for the handler in question also @@ -145,7 +145,7 @@ {fun((Log,Extra) -> Log | stop | ignore), Extra}

The configuration parameter filter_default - specifies the behavior if all filters return ignore. + specifies the behaviour if all filters return ignore. filter_default is by default set to log.

The Extra parameter may contain any data that the @@ -250,52 +250,58 @@

Logger can be configured either when the system starts through configuration parameters, - or at run-time by using the logger + 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 run-time, such as the logging level.

+ has to be changed at run-time, such as the log level.

- Application configuration parameters + Kernel Configuration Parameters

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

-
+ - logger -

The logger application configuration parameter is used to configure - three different logger aspects; handlers, logger filters and module levels. +

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 will allow another application + +

Disable the default handler. This allows another application to add its own default handler. See - logger:add_handlers/1 for more details. + 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) had been - called. - Filters = {filters, FilterDefault, [Filter]}
+ +

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 is allowed of this option. - ModuleLevel - {module_level, Level, [Module]}, - this option configures the - module log level to be used. It is possible to have multiple - module_level entries. + +

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 a the file "logs/erlang.log"

+

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

[{kernel, [{logger, @@ -338,7 +344,6 @@
-
@@ -441,36 +446,30 @@ error_logger in the following ways:

- Legacy event handlers - -

To use event handlers written for error_logger, just - add your event handler with

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

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

Note that this handler will ignore events that do not - originate from the old 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 note that error_logger is not overload - protected.

-
- Logger API + API for Logging

The old error_logger API still exists, but should only be used by legacy code. It will be removed in a later release.

+

Calls + to + error_logger:error_report/1,2, + + error_logger:error_msg/1,2, and + corresponding functions for warning and info messages, are + all forwarded to Logger as calls + to + logger:log(Level,Report,Metadata).

+

Level = error | warning | info and is taken + from the function name. Report contains the actual + log message, and Metadata contains additional + information which can be used for creating backwards + compatible events for legacy error_logger event + handlers, see + section Legacy + Event Handlers.

- Output format + Output Format

To get log events on the same format as produced by error_logger_tty_h and error_logger_file_h, @@ -478,13 +477,13 @@ error_logger:add_report_handler/1,2. configuration parameter legacy_header=>true. This is also the default.

- Default format of log events from OTP + Default Format of Log Events from OTP

By default, all log events originating from within OTP, except the former so called "SASL reports", look the same as before.

- SASL reports + SASL Reports

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

@@ -494,32 +493,63 @@ error_logger:add_report_handler/1,2. named sasl_report_tty_h and sasl_report_file_h.

The destination of these log events were configured by - environment variables for the SASL application.

+ SASL + configuration parameters.

Due to the specific event handlers, the output format slightly differed from other log events.

As of OTP-21, the concept of SASL reports is removed, - meaning that the default behavior is as follows:

+ meaning that the default behaviour is as follows:

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 environment - variable logger_log_progress. + enabled with the Kernel configuration + parameter + logger_log_progress.
The output format is the same for all log events. -

If the old behavior is preferred, the kernel environment - variable logger_sasl_compatible can be set - to true. The old SASL environment variables can then - be used as before, and the SASL reports will only be printed - if the SASL application is running - through a second log - handler named sasl_h.

+

If the old behaviour is preferred, the Kernel configuation + parameter + logger_sasl_compatible can be set + to true. The + old SASL + configuration parameters can then be used as + before, and the SASL reports will only be printed if the + SASL application is running, through a second log handler + named sasl_h.

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

+

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

+ + Legacy Event Handlers + +

To use event handlers written for error_logger, just + add your event handler with

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

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

Notice that this handler will ignore events that do not + originate from the old 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.

@@ -535,14 +565,14 @@ error_logger:add_report_handler/1,2. converting the report to a format string and arguments. The handler might also do a custom conversion if the default format is not desired.

-

logger does, to a certain extent, check its input data +

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.

-

If a filter or handler still crashes, logger will remove the +

If a filter or handler still crashes, Logger will remove the filter or handler in question from the configuration, and then print a short error message on the console. A debug event containing the crash reason and other details is also issued, @@ -552,13 +582,13 @@ error_logger:add_report_handler/1,2.

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

When starting an erlang node, the default behavior is that all +

When starting an erlang node, the default behaviour is that all log events with level info and above are logged to the console. 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 +

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

@@ -575,9 +605,9 @@ ok
#Fun<erl_eval.12.98642416> 4> logger:add_handler_filter(debug_handler,allow_debug,{Fun,[]}). ok -

And finally, we need to make sure that the logger itself allows +

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

+ log level:

 5> logger:set_logger_config(level,debug).
 ok
@@ -599,21 +629,22 @@ adding_handler(logger:handler_id(),logger:config()) -> {ok,logger:config()} | {e removing_handler(logger:handler_id(),logger:config()) -> ok changing_config(logger:handler_id(),logger:config(),logger:config()) -> {ok,logger:config()} | {error,term()}
-

When logger:add_handler(Id,Module,Config) is called, logger - will first call Module:adding_handler(Id,Config), and if it - returns {ok,NewConfig} the NewConfig is written to the +

When logger:add_handler(Id,Module,Config) is called, Logger + will first call Module:adding_handler(Id,Config), and if it + returns {ok,NewConfig}, NewConfig is written to the configuration database. After this, the handler may receive log - events as calls to Module:log/2.

+ events as calls to Module:log/2.

A handler can be removed by calling - logger:remove_handler(Id). logger will call - Module:removing_handler(Id,Config), and then remove the handler's - configuration from the configuration database.

-

When logger:set_handler_config is called, logger calls - Module:changing_config(Id,OldConfig,NewConfig). If this function - returns ok, the NewConfig is written to the configuration - database.

- -

A simple handler which prints to the console could be + logger:remove_handler(Id). Logger will call + Module:removing_handler(Id,Config), and then remove the + handler's configuration from the configuration database.

+

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

+ +

A simple handler that prints to the console could be implemented as follows:

-module(myhandler). @@ -720,7 +751,7 @@ do_log(Fd,Log,#{formatter:={FModule,FConfig}}) -> and as long as the length of the message queue is lower, all log requests are handled asynchronously. This simply means that the process sending the log request (by calling a log function in the - logger API) does not wait for a response from the handler but + Logger API) does not wait for a response from the handler but continues executing immediately after the request (i.e. it will not be affected by the time it takes the handler to print to the log device). If the message queue grows larger than this value, however, @@ -876,7 +907,14 @@ logger:add_handler(my_disk_log_h, logger_disk_log_h,
See Also -

error_logger(3), - SASL(6)

+

+ disk_log(3), + error_logger(3), + logger(3), + logger_disk_log_h(3), + logger_filters(3), + logger_formatter(3), + logger_std_h(3), + sasl(6)

diff --git a/lib/kernel/doc/src/logger_disk_log_h.xml b/lib/kernel/doc/src/logger_disk_log_h.xml index 440ae28e5d..20b49b8ca0 100644 --- a/lib/kernel/doc/src/logger_disk_log_h.xml +++ b/lib/kernel/doc/src/logger_disk_log_h.xml @@ -33,21 +33,21 @@ logger_disk_log_h.xml logger_disk_log_h - A disk_log based handler for the Logger - application. + A disk_log based handler for the Logger. -

This is a handler for the Logger application that offers circular - (wrapped) logs by using the disk_log application. Multiple instances - of this handler can be added to logger, and each instance will print to +

This is a handler for Logger that offers circular + (wrapped) logs by using disk_log. + Multiple instances + of this handler can be added to Logger, and each instance prints to its own disk_log file, created with the name and settings specified in 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 startup 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 + process and the Kernel application alive during a high load of log requests. How this feature works, and how to modify the configuration, is described in the User's Guide @@ -121,7 +121,7 @@ logger:add_handler(my_disk_log_h, logger_disk_log_h, #{filesync_repeat_interval => 1000}}).

In order to use the disk_log handler instead of the default standard - handler when starting en Erlang node, change the Kernel default logger to + handler when starting an Erlang node, change the Kernel default logger to use disk_log. Example:

erl -kernel logger '[{handler,default,logger_disk_log_h, @@ -141,6 +141,12 @@ erl -kernel logger '[{handler,default,logger_disk_log_h, +
+ See Also +

logger(3)

+

logger_std_h(3)

+

disk_log(3)

+
diff --git a/lib/kernel/doc/src/logger_formatter.xml b/lib/kernel/doc/src/logger_formatter.xml index 370d61d338..ee43634cf9 100644 --- a/lib/kernel/doc/src/logger_formatter.xml +++ b/lib/kernel/doc/src/logger_formatter.xml @@ -39,7 +39,8 @@

Each log handler has a configured formatter specified as a module and a configuration term. The purpose of the formatter is to translate the log events to a final printable string - (unicode:chardata()) which can be written to the output + (unicode:chardata() + ) which can be written to the output device of the handler.

logger_formatter is the default formatter used by Logger.

@@ -47,7 +48,8 @@
Configuration -

The configuration term for logger_formatter is a map, +

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

@@ -55,7 +57,7 @@

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

@@ -99,7 +101,7 @@ added by the template parameter are not replaced.

Default is true.

- legacy_header = boolen() + legacy_header = boolean()

If set to true a header field is added to logger_formatter's part of Metadata. The value of @@ -181,8 +183,8 @@ to "+02:00".

The default value is an empty string, meaning that timestamps are displayed in local time. However, for - backwards compatibility, if the SASL environment - variable + backwards compatibility, if the SASL configuration + parameter utc_log=true, the default is changed to "Z", meaning that timestamps are displayed in UTC.

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

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

Example log entry:

-2018-05-16T11:55:50.448382+02:00 error: +=ERROR REPORT==== 17-May-2018::18:30:19.453447 === name: my_name exit_reason: "It crashed" -

Notice that all eight levels might occur in the heading, +

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.

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

Default 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 + differs in that there is only one line after the + heading:

+ +=ERROR REPORT==== 17-May-2018::18:31:06.952665 === +name: my_name, exit_reason: "It crashed" +
+ + legacy_header=false, single_line=true

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

Example log entry:

- 2018-05-16T11:55:50.448382+02:00 error: 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 @@ -236,7 +252,7 @@ exit_reason: "It crashed"

Example log entry:

-2018-05-16T11:55:50.448382+02:00 error: +2018-05-17T18:32:20.105422+02:00 error: name: my_name exit_reason: "It crashed" diff --git a/lib/kernel/doc/src/logger_std_h.xml b/lib/kernel/doc/src/logger_std_h.xml index bf23d874c8..a4f2848037 100644 --- a/lib/kernel/doc/src/logger_std_h.xml +++ b/lib/kernel/doc/src/logger_std_h.xml @@ -33,17 +33,17 @@ logger_std_h.xml logger_std_h - Default handler for the Logger application. + Default handler for Logger. -

This is the default handler for the Logger - application. Multiple instances of this handler can be added to - logger, and each instance will print logs to standard_io, +

This is the default handler for Logger. + Multiple instances of this handler can be added to + Logger, and each instance will print logs to standard_io, standard_error or to file. The default instance that starts - with kernel is named default - which is the name to be used + with Kernel is named default - which is the name to be used for reconfiguration.

The handler has an overload protection mechanism that will keep the handler - process and the kernel application alive during a high load of log + process and the Kernel application alive during a high load of log requests. How this feature works, and how to modify the configuration, is described in the User's Guide @@ -104,7 +104,7 @@ logger:add_handler(my_standard_h, logger_std_h, 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, + 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, @@ -127,6 +127,11 @@ erl -kernel logger '[{handler,default,logger_std_h, +
+ See Also +

logger(3)

+

logger_disk_log_h(3)

+
-- cgit v1.2.3