Skip to content

Commit 2519c7a

Browse files
Added block to main article.
1 parent 3065622 commit 2519c7a

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

logging.rst

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,49 @@ specific channel (``app`` by default), use the ``monolog.logger`` tag with the
323323
``channel`` property as explained in the
324324
:ref:`Dependency Injection reference <dic_tags-monolog>`.
325325

326+
How to Disable Microseconds Precision (for a Performance Boost)
327+
---------------------------------------------------------------
328+
329+
Setting the parameter ``use_microseconds`` to ``false`` forces the logger to reduce
330+
the precision in the ``datetime`` field of the log messages from microsecond to second,
331+
avoiding a call to the ``microtime(true)`` function and the subsequent parsing.
332+
Disabling the use of microseconds can provide a small performance gain speeding up the
333+
log generation. This is recommended for systems that generate a large number of log events.
334+
335+
.. configuration-block::
336+
337+
.. code-block:: yaml
338+
339+
# config/packages/monolog.yaml
340+
monolog:
341+
use_microseconds: false
342+
# ...
343+
344+
.. code-block:: xml
345+
346+
<!-- config/packages/monolog.xml -->
347+
<?xml version="1.0" encoding="UTF-8" ?>
348+
<container xmlns="http://symfony.com/schema/dic/services"
349+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
350+
xmlns:monolog="http://symfony.com/schema/dic/monolog"
351+
xsi:schemaLocation="http://symfony.com/schema/dic/services
352+
http://symfony.com/schema/dic/services/services-1.0.xsd
353+
http://symfony.com/schema/dic/monolog
354+
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
355+
356+
<monolog:config use-microseconds="false">
357+
<!-- ... -->
358+
</monolog:config>
359+
</container>
360+
361+
.. code-block:: php
362+
363+
// config/packages/monolog.php
364+
$container->loadFromExtension('monolog', array(
365+
'use_microseconds' => false,
366+
// ...
367+
));
368+
326369
Adding extra Data to each Log (e.g. a unique request token)
327370
-----------------------------------------------------------
328371

@@ -343,7 +386,6 @@ Learn more
343386
logging/processors
344387
logging/monolog_regex_based_excludes
345388
logging/monolog_console
346-
logging/disable_microsecond_precision
347389

348390
.. _Monolog: https://github.com/Seldaek/monolog
349391
.. _LoggerInterface: https://github.com/php-fig/log/blob/master/Psr/Log/LoggerInterface.php

0 commit comments

Comments
 (0)