Модуль log
Tarantool provides a set of options used to configure logging
in various ways: you can set a level of logging, specify where to send the log’s output,
configure a log format, and so on.
The log
module allows you to configure logging in your application and
provides additional capabilities, for example, logging custom messages and
rotating log files.
Ниже приведен перечень всех функций и элементов модуля log
.
Имя | Назначение |
---|---|
log.cfg({}) | Configures a logger |
log.error() log.warn() log.info() log.verbose() log.debug() |
Logs a message with the specified level |
log.pid() | Gets the PID of a logger |
log.rotate() | Rotates a log file |
-
log.
cfg
({})¶ Allows you to configure logging options. The following options are available:
level
: Specifies the level of detail the log has.Learn more: log_level.
log
: Specifies where to send the log’s output, for example, to a file, pipe, or system logger.Learn more: log.
nonblock
: If true, Tarantool does not block during logging when the system is not ready for writing, and drops the message instead.Learn more: log_nonblock.
format
: Specifies the log format: „plain“ or „json“.Learn more: log_format.
The example below shows how to set the log level to „debug“ and how to send the resulting log to the „tarantool.log“ file:
log = require('log') log.cfg{ level='debug', log='tarantool.log'}
-
log.
error
(message)¶ -
log.
warn
(message)¶ -
log.
info
(message)¶ -
log.
verbose
(message)¶ -
log.
debug
(message)¶ Logs a message with the specified logging level. You can learn more about the available levels from the log_level property description.
The example below shows how to log a message with the
info
level:log = require('log') log.info('Hello, world!')
Параметры: - message (
any
) –A log message.
- A message can be a string.
- A message may contain C-style format specifiers
%d
or%s
. Example:box.cfg{} log = require('log') log.info('Info %s', box.info.version)
- A message may be a scalar data type or a table. Example:
log = require('log') log.error({500,'Internal error'})
возвращает: nil
Выходное значение будет представлять собой строку в журнале, которая содержит следующее:
- the current timestamp
- a module name
- „E“, „W“, „I“, „V“ or „D“ depending on the called function
message
Note that the message will not be logged if the severity level corresponding to the called function is less than log_level.
- message (
-
log.
pid
()¶ возвращает: A PID of a logger. You can use this PID to send a signal to a log rotation program, so it can rotate logs.
-
log.
rotate
()¶ Rotates the log. For example, you need to call this function to continue logging after a log rotation program renames or moves a file with the latest logs.
возвращает: nil