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:
The value is set when the handler is added, and it cannot be changed in runtime.
Defaults to standard_io, unless parameter file is given, in which case it defaults to file.
The value is set when the handler is added, and it cannot be changed in runtime.
Defaults to the same name as the handler identity, in the current directory.
Log files are always UTF-8 encoded. The encoding cannot be changed by setting the mode {encoding,Encoding}.
The value is set when the handler is added, and it cannot be changed in runtime.
Defaults to [raw,append,delayed_write].
Defaults to infinity.
The log archives are named FileName.0, FileName.1, ... FileName.N, where FileName is the name of the current log file. FileName.0 is the newest of the archives. The maximum value for N is the value of max_no_files minus 1.
Notice that setting this value to 0 does not turn off rotation. It only specifies that no archives are kept.
Defaults to 0.
compress_on_rotate has no meaning if max_no_bytes has the value infinity.
Defaults to false.
In order to allow minimizing the performance loss, the file_check parameter can be set to a positive integer value, N. The handler will then skip reading the file information prior to writing, as long as no more than N milliseconds have passed since it was last read.
Notice that the risk of losing log events grows when the file_check value grows.
Defaults to 0.
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, file, or modes parameters must not be modified.
Example of adding a standard handler:
logger:add_handler(my_standard_h, logger_std_h,
#{config => #{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 => #{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:
Write buffered data to disk.
kernel 8.5.3 | Ericsson AB |