From 343298ef2ef349e7b74265751fd6151ada224470 Mon Sep 17 00:00:00 2001
From: Peter Andersson
The API for logging consists of a set
of
As long as the length of the message queue is lower than this
value, all log events are handled asynchronously. This means that
- the process sending the log event, by calling a log function in the
- Logger API, does not wait for a response from the handler, but
- continues executing immediately after the event is sent (that is, it
- is not affected by the time it takes the handler to print the event
- to the log device). If the message queue grows larger than this value,
+ the client process sending the log event, by calling a log function
+ in the
Default value of the threshold:
Defaults to
When the message queue grows larger than this threshold, the handler switches to a mode in which it drops all new events that - senders want to send. Dropping an event in ths mode, means that the - log function never sends a message to the handler, but returns - without taking any action. The handler keeps logging events already - in the message queue, and when the length of the message queue is - reduced to a level below the threshold, synchronous or asynchronous - mode is resumed. Note that when the handler activates, or deactivates, - drop mode, information about it is printed to the log.
-Default value of the threshold:
Defaults to
If the length of the message queue grows larger than this threshold, - a flush (delete) operation takes place. To flush events, the handler receives - the messages in the process mailbox in a loop without logging (that is, the - handler deletes the events). Processes waiting for a response from a - synchronous log request will receive a reply from the handler indicating - that the request has been dropped. The handler process will set its own priority - to high during the flush loop to make sure that no new events come in - during the operation. Note that after the flush operation is performed, - the handler prints information in the log about how many events have been - deleted
-Default value of the threshold:
Defaults to
During high load scenarios, the length of the handler message queue rarely grows in a linear and predictable way. Instead, whenever the - handler process gets scheduled in, it can have an almost arbitrary number - of messages waiting in the mailbox. It's for this reason that the overload + handler process is scheduled in, it can have an almost arbitrary number + of messages waiting in the message queue. It is for this reason that the overload protection mechanism is focused on acting quickly, and quite drastically, such as immediately dropping or flushing messages, when a large queue length is detected.
@@ -1202,38 +1205,36 @@ do_log(Fd, LogEvent, #{formatter := {FModule, FConfig}}) ->The values of the previously listed thresholds can be specified by the user. This way, a handler can be configured to, for example, not drop or flush messages unless the message queue length of the handler process grows extremely - large. Note that large amounts of memory can be required for the node under such + large. Notice that large amounts of memory can be required for the node under such circumstances. Another example of user configuration is when, for performance - reasons, the logging processes must never get blocked by synchronous log requests. - It's possible, perhaps, that dropping or flushing events is still acceptable (since - it does not affect the performance of the processes sending the log events).
+ reasons, the client processes must never be blocked by synchronous log requests. + It is possible, perhaps, that dropping or flushing events is still acceptable, since + it does not affect the performance of the client processes sending the log events.A configuration example:
logger:add_handler(my_standard_h, logger_std_h,
- #{config =>
- #{type => {file,"./system_info.log"},
- sync_mode_qlen => 100,
- drop_mode_qlen => 1000,
- flush_qlen => 2000}}).
+ #{config => #{type => {file,"./system_info.log"},
+ sync_mode_qlen => 100,
+ drop_mode_qlen => 1000,
+ flush_qlen => 2000}}).
Large bursts of log events (that is, many events received by the handler - under a short period of time), can potentially cause problems, such as:
+Large bursts of log events - many events received by the handler + under a short period of time - can potentially cause problems, such as:
For this reason, both built-in handlers offer the possibility to specify the maximum number of events to be handled within a certain time frame. With this burst control feature enabled, the handler can avoid choking the log with - massive amounts of printouts. These are the configuration parameters:
- + massive amounts of printouts. The configuration parameters are:This is the maximum number of events to handle within a
-
Defaults to
See the previous description of
See the previous description of
Defaults to
A configuration example:
logger:add_handler(my_disk_log_h, logger_disk_log_h,
- #{config =>
- #{file => "./my_disk_log",
- burst_limit_enable => true,
- burst_limit_max_count => 20,
- burst_limit_window_time => 500}}).
+ #{config => #{file => "./my_disk_log",
+ burst_limit_enable => true,
+ burst_limit_max_count => 20,
+ burst_limit_window_time => 500}}).
This is the maximum allowed queue length. If the mailbox grows larger - than this, the handler process gets terminated.
+This is the maximum allowed queue length. If the message queue grows + larger than this, the handler process is terminated.
Defaults to
This is the maximum memory size that the handler process is allowed to use. - If the handler grows larger than this, the process gets terminated.
+ If the handler grows larger than this, the process is terminated.Defaults to
If the handler gets terminated, it can restart automatically after a
- delay, specified in milliseconds. The value
If the handler is terminated, it restarts automatically after a
+ delay specified in milliseconds. The value
Defaults to
If the handler process gets terminated because of overload, information about - this event is printed in the log. Information about when a restart has taken - place, and the handler is back in action, is also printed.
+If the handler process is terminated because of overload, it prints + information about it in the log. It also prints information about when a + restart has taken place, and the handler is back in action.
+The sizes of the log events affect the memory needs of the handler.
+ For information about how to limit the size of log events, see the
+
This is a handler for Logger that offers circular
(wrapped) logs by using
The default standard handler,
This is the full name of the disk_log log file. The option
+ This is the full name of the disk log file. The option
corresponds to the This is the disk_log type, This is the disk log type, This is the maximum number of files that disk_log will use
+ This is the maximum number of files that disk_log uses
for its circular logging. The option
corresponds to the Defaults to Defaults to The setting has no effect on a halt log. This is the maximum number of bytes that will be written to
- a log file before disk_log proceeds with the next file in order (or
- generates an error in case of a full halt log). The option
+ This is the maximum number of bytes that is written to
+ a log file before disk_log proceeds with the next file in order, or
+ generates an error in case of a full halt log. The option
corresponds to the
Note that when changing the configuration of the handler in runtime, by
- calling
-
Notice that when changing the configuration of the handler in runtime, the
+ disk_log options (
Example of adding a disk_log handler:
logger:add_handler(my_disk_log_h, logger_disk_log_h,
- #{level => error,
- filter_default => log,
- config => #{file => "./my_disk_log",
+ #{config => #{file => "./my_disk_log",
type => wrap,
max_no_files => 4,
max_no_bytes => 10000},
@@ -131,7 +128,7 @@ logger:add_handler(my_disk_log_h, logger_disk_log_h,
To use the disk_log handler instead of the default standard handler when starting an Erlang node, change the Kernel default logger to - use disk_log. Example:
+ use
erl -kernel logger '[{handler,default,logger_disk_log_h,
#{config => #{file => "./system_disk_log"}}}]'
diff --git a/lib/kernel/doc/src/logger_std_h.xml b/lib/kernel/doc/src/logger_std_h.xml
index 08667ae7f9..95b4baf160 100644
--- a/lib/kernel/doc/src/logger_std_h.xml
+++ b/lib/kernel/doc/src/logger_std_h.xml
@@ -33,15 +33,13 @@
logger_std_h.xml
logger_std_h
- Default handler for Logger.
+ Standard handler for Logger.
- This is the default handler for Logger.
+
This is the standard handler for Logger.
Multiple instances of this handler can be added to
Logger, and each instance prints 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
- for reconfiguration.
+ standard_error , or to file.
The handler has an overload protection mechanism that keeps the handler
process and the Kernel application alive during high loads of log
events. How overload protection works, and how to configure it, is
@@ -62,12 +60,12 @@
This has the value standard_io , standard_error ,
{file,LogFileName} , or {file,LogFileName,LogFileOpts} .
Defaults to standard_io .
- It is recommended to not specify LogFileOpts , unless absolutely
- necessary. The default options used by the handler to open a file for logging are:
- raw , append and delayed_write . Note that the standard
- handler does not have support for circular logging. Use the
- logger_disk_log_h
- handler for this.
+ It is recommended not to specify LogFileOpts unless absolutely
+ necessary. The default options used by the handler to open a file for logging are
+ raw , append , and delayed_write . Notice that the standard
+ handler does not have support for circular logging. Use the disk_log handler,
+ logger_disk_log_h ,
+ for this.
filesync_repeat_interval
-
@@ -77,8 +75,8 @@
actually been logged.
Defaults to 5000 milliseconds.
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
+ is disabled, and it is the operating system settings that determine
+ how quickly or slowly data is written to disk. The user can also call
the filesync/1
function to perform a file sync.
@@ -88,32 +86,25 @@
standard handler and the disk_log handler, and are documented in the
User's Guide
.
- Note that if changing the configuration of the handler in runtime, by
- calling
- logger:set_handler_config/2
- , or
- logger:set_handler_config/3
- ,
+
Notice that if changing the configuration of the handler in runtime,
the type parameter must not be modified.
Example of adding a standard handler:
logger:add_handler(my_standard_h, logger_std_h,
- #{level => info,
- filter_default => log,
- config =>
- #{type => {file,"./system_info.log"},
- filesync_repeat_interval => 1000}}).
+ #{config => #{type => {file,"./system_info.log"},
+ filesync_repeat_interval => 1000}}).
- To set the default handler (that starts initially with
- the Kernel application) to log to file instead of standard_io ,
+
To set the default handler, that starts initially with
+ the Kernel application, to log to file instead of standard_io ,
change the Kernel default logger configuration. Example:
erl -kernel logger '[{handler,default,logger_std_h,
#{config => #{type => {file,"./log.log"}}}}]'
An example of how to replace the standard handler with a disk_log handler
- at start up can be found in the manual of
- logger_disk_log_h .
+ at startup is found in the
+ logger_disk_log_h
+ manual.
--
cgit v1.2.3