DOKK / manpages / debian 10 / erlang-manpages / logger_std_h.3erl.en
logger_std_h(3erl) Erlang Module Definition logger_std_h(3erl)

logger_std_h - 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}.

If LogFileOpts is specified, it replaces the default list of options used when opening the log file. The default list is [raw,append,delayed_write]. One reason to do so can be to change append to, for example, write, ensuring that the old log is truncated when a node is restarted. See the reference manual for file:open/2 for more information about file options.

Log files are always UTF-8 encoded. The encoding can not be changed by setting the option {encoding,Encoding} in LogFileOpts.

Notice that the standard handler does not have support for circular logging. Use the disk_log handler, logger_disk_log_h, for this.

The value is set when the handler is added, and it can not be changed in runtime.

Defaults to standard_io.

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.

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.

Defaults to 5000 milliseconds.

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}


Types:

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

Write buffered data to disk.

logger(3erl), logger_disk_log_h(3erl)

kernel 6.2 Ericsson AB