Reference Manual

Version 6.0

Table of Contents




Module Summary

A disk_log based handler for the Logger application.


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 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. 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 requests. How this feature works, and how to modify the configuration, is described in the User's Guide.

To add a new instance of the disk_log handler, use logger:add_handler/3. The handler configuration argument is a map which may contain general configuration parameters, as documented in the User's Guide, 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 dlog_option().

Parameters in the disk_log_opts map:

This is the full name of the disk_log log file.
This is the disk_log type, wrap or halt. The default value is wrap.
This is the maximum number of files that disk_log will use for its circular logging. The default value is 10. (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 default value for a wrap log is 1048576 bytes, and infinity for a halt log.

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


This value (in milliseconds) specifies how often the handler will do a disk_log sync operation in order to make sure that buffered data gets written to disk. The handler will repeatedly attempt this operation, but only perform it if something has actually been logged 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 function to perform a disk_log sync.

There are a number of other configuration parameters available, that are to be used for customizing the overload protection behaviour. The same parameters are used both in the standard handler and the disk_log handler, and are documented in the User's Guide.

Note that when changing the configuration of the handler in runtime, by calling logger:set_handler_config/2 or logger:set_handler_config/3, the disk_log_opts settings may not be modified.

Example of adding a disk_log handler:

logger:add_handler(my_disk_log_h, logger_disk_log_h,
                   #{level => error,
                     filter_default => log,
                     disk_log_opts =>
                              #{file => "./my_disk_log",
                                type => wrap,
                                max_no_files => 4,
                                max_no_bytes => 10000},
                     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, use the kernel configuration parameter logger_dest with value {disk_log,FileName}. Example:

erl -kernel logger_dest '{disk_log,"./system_disk_log"}'


disk_log_sync(Name) -> ok | {error, Reason}


Name = atom()
Reason = handler_busy | {badarg, term()}

Write buffered data to disk.