Module log
The Tarantool server puts all diagnostic messages in a log file specified by
the log configuration parameter. Diagnostic
messages may be either system-generated by the server’s internal code, or
user-generated with the log.log_level_function_name
function.
As explained in the description of log_format configuration setting, there are two possible formats for log entries:
- ‘plain’ (the default), or
- ‘json’ (with more detail and with JSON labels).
Here is what a log entry looks like after box.cfg{log_format='plain'}
:
2017-10-16 11:36:01.508 [18081] main/101/interactive I> set 'log_format' configuration option to "plain"
Here is what a log entry looks like after box.cfg{log_format='json'}
:
{"time": "2017-10-16T11:36:17.996-0600",
"level": "INFO",
"message": "set 'log_format' configuration option to \"json\"",
"pid": 18081,|
"cord_name": "main",
"fiber_id": 101,
"fiber_name": "interactive",
"file": "builtin\/box\/load_cfg.lua",
"line": 317}
Below is a list of all log
functions.
Name | Use |
---|---|
log.error() log.warn() log.info() log.verbose() log.debug() |
Write a user-generated message to a log file |
log.logger_pid() | Get the PID of a logger |
log.rotate() | Rotate a log file |
-
log.
error
(message)¶ -
log.
warn
(message)¶ -
log.
info
(message)¶ -
log.
verbose
(message)¶ -
log.
debug
(message)¶ Output a user-generated message to the log file, given log_level_function_name =
error
orwarn
orinfo
orverbose
ordebug
.As explained in the description of the configuration setting for log_level, there are seven levels of detail:
- 1 –
SYSERROR
- 2 –
ERROR
– this corresponds tolog.error(...)
- 3 –
CRITICAL
- 4 –
WARNING
– this corresponds tolog.warn(...)
- 5 –
INFO
– this corresponds tolog.info(...)
- 6 –
VERBOSE
– this corresponds tolog.verbose(...)
- 7 –
DEBUG
– this corresponds tolog.debug(...)
For example, if
box.cfg.log_level
is currently 5 (the default value), thenlog.error(...)
,log.warn(...)
andlog.info(...)
messages will go to the log file. However,log.verbose(...)
andlog.debug(...)
messages will not go to the log file, because they correspond to higher levels of detail.Parameters: - message (
any
) –Usually a string.
Messages may contain C-style format specifiers %d or %s, so
log.error('...%d...%s', x, y)
will work ifx
is a number andy
is a string.Less commonly, messages may be other scalar data types, or even tables. So
log.error({'x',18.7,true})
will work.
Return: nil
The actual output will be a line in the log, containing:
- the current timestamp,
- a module name,
- ‘E’, ‘W’, ‘I’, ‘V’ or ‘D’ depending on
log_level_function_name
, and message
.
Output will not occur if
log_level_function_name
is for a type greater than log_level.- 1 –
-
log.
logger_pid
()¶ Return: PID of a logger
-
log.
rotate
()¶ Rotate the log.
Return: nil
$ tarantool
tarantool> box.cfg{log_level=3, log='tarantool.txt'}
tarantool> log = require('log')
tarantool> log.error('Error')
tarantool> log.info('Info %s', box.info.version)
tarantool> os.exit()
$ less tarantool.txt
2017-09-20 ... [68617] main/101/interactive C> version 1.7.5-31-ge939c6ea6
2017-09-20 ... [68617] main/101/interactive C> log level 3
2017-09-20 ... [68617] main/101/interactive [C]:-1 E> Error
The ‘Error’ line is visible in tarantool.txt
preceded by the letter E.
The ‘Info’ line is not present because the log_level
is 3.