Skip to content

Commit 7a3e184

Browse files
committed
Logging module API
1 parent 362e35c commit 7a3e184

File tree

1 file changed

+42
-37
lines changed

1 file changed

+42
-37
lines changed

doc/reference/reference_lua/log.rst

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Below is a list of all ``log`` functions.
6464

6565
* ``level``: Specifies the level of detail the log has.
6666

67-
Learn more: :ref:`log_level <cfg_logging-log_level>`.
67+
Learn more: :ref:`log.level <configuration_reference_log_level>`.
6868

6969
* ``log``: Specifies where to send the log's output, for example,
7070
to a file, pipe, or system logger.
@@ -74,29 +74,26 @@ Below is a list of all ``log`` functions.
7474
* ``nonblock``: If **true**, Tarantool does not block during logging when the system
7575
is not ready for writing, and drops the message instead.
7676

77-
Learn more: :ref:`log_nonblock <cfg_logging-log_nonblock>`.
77+
Learn more: :ref:`log.nonblock <configuration_reference_log_nonblock>`.
7878

7979
* ``format``: Specifies the log format: 'plain' or 'json'.
8080

81-
Learn more: :ref:`log_format <cfg_logging-log_format>`.
81+
Learn more: :ref:`log.format <configuration_reference_log_format>`.
8282

8383
* ``modules``: Configures the specified log levels for different modules.
8484

85-
Learn more: :ref:`log_modules <cfg_logging-log_modules>`.
85+
Learn more: :ref:`log.modules <configuration_reference_log_modules>`.
8686

87-
The example below shows how to set the log level to 'debug' and how to send the resulting log
88-
to the 'tarantool.log' file:
87+
**Example**
8988

90-
.. code-block:: lua
89+
The example below shows how to set the log level to ``verbose``:
9190

92-
log = require('log')
93-
log.cfg{ level='debug', log='tarantool.log'}
94-
95-
.. NOTE::
91+
.. literalinclude:: /code_snippets/test/logging/log_test.lua
92+
:language: lua
93+
:start-at: local log = require
94+
:end-at: log.cfg
95+
:dedent:
9696

97-
Note that calling ``log.cfg()`` before ``box.cfg()`` takes into account
98-
logging options specified using :ref:`environment variables <box-cfg-params-env>`,
99-
such as ``TT_LOG`` and ``TT_LOG_LEVEL``.
10097

10198
.. _log-ug_message:
10299

@@ -108,13 +105,16 @@ Below is a list of all ``log`` functions.
108105

109106
Log a message with the specified logging level.
110107
You can learn more about the available levels from the
111-
:ref:`log_level <cfg_logging-log_level>` property description.
108+
:ref:`log.level <configuration_reference_log_level>` option description.
109+
110+
**Example**
112111

113-
The example below shows how to log a message with the ``info`` level:
112+
The example below shows how to log a message with the ``warn`` level:
114113

115114
.. literalinclude:: /code_snippets/test/logging/log_test.lua
116115
:language: lua
117-
:lines: 13-21
116+
:start-at: log.warn
117+
:end-at: log.warn
118118
:dedent:
119119

120120
:param any message: A log message.
@@ -123,18 +123,19 @@ Below is a list of all ``log`` functions.
123123

124124
* A message may contain C-style format specifiers ``%d`` or ``%s``. Example:
125125

126-
.. code-block:: lua
127-
128-
box.cfg{}
129-
log = require('log')
130-
log.info('Info %s', box.info.version)
126+
.. literalinclude:: /code_snippets/test/logging/log_test.lua
127+
:language: lua
128+
:start-at: log.info
129+
:end-at: log.info
130+
:dedent:
131131

132132
* A message may be a scalar data type or a table. Example:
133133

134-
.. code-block:: lua
135-
136-
log = require('log')
137-
log.error({500,'Internal error'})
134+
.. literalinclude:: /code_snippets/test/logging/log_test.lua
135+
:language: lua
136+
:start-at: log.error
137+
:end-at: log.error
138+
:dedent:
138139

139140
:return: nil
140141

@@ -146,7 +147,7 @@ Below is a list of all ``log`` functions.
146147
* ``message``
147148

148149
Note that the message will not be logged if the severity level corresponding to
149-
the called function is less than :ref:`log_level <cfg_logging-log_level>`.
150+
the called function is less than :ref:`log.level <configuration_reference_log_level>`.
150151

151152
.. _log-pid:
152153

@@ -176,28 +177,32 @@ Below is a list of all ``log`` functions.
176177
:param string name: a logger name
177178
:return: a logger instance
178179

179-
**Example:**
180+
**Example**
180181

181-
The code snippet below shows how to set the ``verbose`` level for ``module1`` and the ``error`` level for ``module2``:
182+
This example shows how to set the ``verbose`` level for ``module1`` and the ``error`` level for ``module2`` in a configuration file:
182183

183-
.. literalinclude:: /code_snippets/test/logging/log_new_modules_test.lua
184-
:language: lua
185-
:lines: 9-13
184+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/log_new_modules/config.yaml
185+
:language: yaml
186+
:start-at: log:
187+
:end-at: app.lua
186188
:dedent:
187189

188-
To create the ``module1`` and ``module2`` loggers, call the ``new()`` function:
190+
To create the ``module1`` and ``module2`` loggers in your application (``app.lua``), call the ``new()`` function:
189191

190-
.. literalinclude:: /code_snippets/test/logging/log_new_modules_test.lua
192+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/log_new_modules/app.lua
191193
:language: lua
192-
:lines: 17-19
194+
:start-at: Creates new loggers
195+
:end-at: module2_log = require
193196
:dedent:
194197

195198
Then, you can call functions corresponding to different logging levels to make sure
196199
that events with severities above or equal to the given levels are shown:
197200

198-
.. literalinclude:: /code_snippets/test/logging/log_new_modules_test.lua
201+
.. literalinclude:: /code_snippets/snippets/config/instances.enabled/log_new_modules/app.lua
199202
:language: lua
200-
:lines: 21-41
203+
:start-after: module2_log = require
201204
:dedent:
202205

203206
At the same time, the events with severities below the specified levels are swallowed.
207+
208+
Example on GitHub: `log_new_modules <https://github.com/tarantool/doc/tree/latest/doc/code_snippets/snippets/config/instances.enabled/log_new_modules>`_.

0 commit comments

Comments
 (0)