Skip to content

Commit ffeaf77

Browse files
committed
Document logging settings
Resolves #1974
1 parent 327ac30 commit ffeaf77

File tree

1 file changed

+32
-54
lines changed

1 file changed

+32
-54
lines changed

doc/reference/reference_lua/log.rst

+32-54
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ Below is a list of all ``log`` functions.
5757
.. function:: log.cfg({})
5858

5959
Allows you to configure logging options.
60-
The following logging options are available:
60+
The following options are available:
6161

6262
* ``level``: Specifies the level of detail the log has.
63-
This property has the same effect as :ref:`log_level <cfg_logging-log_level>`.
63+
64+
See also: :ref:`log_level <cfg_logging-log_level>`.
6465

6566
* ``log``: Specifies where to to send the log's output, for example,
6667
to a file, pipe, or system logger.
@@ -73,10 +74,9 @@ Below is a list of all ``log`` functions.
7374
See also: :ref:`log_nonblock <cfg_logging-log_nonblock>`
7475

7576
* ``format``: Specifies the log format: 'plain' or 'json'.
76-
7777
See also: :ref:`log_format <cfg_logging-log_format>`
7878

79-
The example below shows how set the log level to 'debug' and how to send the resulting log
79+
The example below shows how to set the log level to 'debug' and how to send the resulting log
8080
to the 'tarantool.log' file:
8181

8282
.. code-block:: lua
@@ -93,36 +93,38 @@ Below is a list of all ``log`` functions.
9393
verbose(message)
9494
debug(message)
9595

96-
Output a user-generated message to the :ref:`log file <cfg_logging-log>`,
97-
given log_level_function_name = ``error`` or ``warn`` or ``info`` or
98-
``verbose`` or ``debug``.
96+
Logs a message with the specified logging level.
97+
You can learn more about the available levels from the
98+
:ref:`log_level <cfg_logging-log_level>` property description.
99+
100+
The example below shows how to log a message with the ``info`` level:
101+
102+
.. code-block:: lua
103+
104+
log = require('log')
105+
log.info('Hello, world!')
106+
107+
:param any message: A log message.
99108

100-
As explained in the description of the configuration setting for
101-
:ref:`log_level <cfg_logging-log_level>`, there are seven levels of detail:
109+
* A message can be a string.
102110

103-
* 1 – ``SYSERROR``
104-
* 2 – ``ERROR`` -- this corresponds to ``log.error(...)``
105-
* 3 – ``CRITICAL``
106-
* 4 – ``WARNING`` -- this corresponds to ``log.warn(...)``
107-
* 5 – ``INFO`` -- this corresponds to ``log.info(...)``
108-
* 6 – ``VERBOSE`` -- this corresponds to ``log.verbose(...)``
109-
* 7 – ``DEBUG`` -- this corresponds to ``log.debug(...)``
111+
* A messages may contain C-style format specifiers ``%d`` or
112+
``%s``. Example:
110113

111-
For example, if ``box.cfg.log_level`` is currently 5 (the default value),
112-
then ``log.error(...)``, ``log.warn(...)`` and ``log.info(...)`` messages
113-
will go to the log file. However, ``log.verbose(...)`` and
114-
``log.debug(...)`` messages will not go to the log file, because they
115-
correspond to higher levels of detail.
114+
.. code-block:: lua
116115
117-
:param any message: Usually a string.
116+
box.cfg{}
117+
log = require('log')
118+
log.info('Info %s', box.info.version)
118119
119-
Messages may contain C-style format specifiers %d or
120-
%s, so :samp:`log.error('...%d...%s', {x}, {y})`
121-
will work if ``x`` is a number and ``y`` is a string.
120+
* A message may be other scalar data types,
121+
or even tables. Example:
122122

123-
Less commonly, messages may be other scalar data types,
124-
or even tables. So :code:`log.error({'x',18.7,true})`
125-
will work.
123+
.. code-block:: lua
124+
125+
box.cfg{}
126+
log = require('log')
127+
log.error({500,'Internal error'})
126128
127129
:return: nil
128130

@@ -141,36 +143,12 @@ Below is a list of all ``log`` functions.
141143

142144
.. function:: logger_pid()
143145

144-
:return: PID of a logger
146+
:return: Returns a PID of a logger.
145147

146148
.. _log-rotate:
147149

148150
.. function:: rotate()
149151

150-
Rotate the log.
152+
Rotates the log.
151153

152154
:return: nil
153-
154-
=================================================
155-
Example
156-
=================================================
157-
158-
.. code-block:: tarantoolsession
159-
160-
$ tarantool
161-
tarantool> box.cfg{log_level=3, log='tarantool.txt'}
162-
tarantool> log = require('log')
163-
tarantool> log.error('Error')
164-
tarantool> log.info('Info %s', box.info.version)
165-
tarantool> os.exit()
166-
167-
.. code-block:: console
168-
169-
$ less tarantool.txt
170-
2017-09-20 ... [68617] main/101/interactive C> version 1.7.5-31-ge939c6ea6
171-
2017-09-20 ... [68617] main/101/interactive C> log level 3
172-
2017-09-20 ... [68617] main/101/interactive [C]:-1 E> Error
173-
174-
The 'Error' line is visible in ``tarantool.txt`` preceded by the letter E.
175-
176-
The 'Info' line is not present because the ``log_level`` is 3.

0 commit comments

Comments
 (0)