Standard 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 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 described in the User's Guide .

To add a new instance of the standard handler, use logger:add_handler/3 . The handler configuration argument is a map which can contain general configuration parameters, as documented in the User's Guide , and handler specific parameters. The specific data is stored in a sub map with the key config, and can contain the following parameters:


This has the value standard_io, standard_error, {file,LogFileName}, or {file,LogFileName,LogFileOpts}.

Defaults to standard_io.

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.


This value, in milliseconds, specifies how often the handler does a file sync operation to write buffered data to disk. The handler attempts the operation repeatedly, but only performs a new sync if something has actually been logged.

Defaults to 5000 milliseconds.

If no_repeat is set as value, the repeated file sync operation 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.

Other configuration parameters exist, 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 .

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,
                   #{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, 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 startup is found in the logger_disk_log_h manual.


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

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

Write buffered data to disk.