How to Disable Microseconds Precision (for a Performance Boost)
Edit this pageWarning: You are browsing the documentation for Symfony 3.0, which is no longer maintained.
Read the updated version of this page for Symfony 6.2 (the current stable version).
How to Disable Microseconds Precision (for a Performance Boost)
2.11
The use_microseconds
option was introduced in MonologBundle 2.11.
Setting the parameter use_microseconds
to false
forces the logger to reduce
the precision in the datetime
field of the log messages from microsecond to second,
avoiding a call to the microtime(true)
function and the subsequent parsing.
Disabling the use of microseconds can provide a small performance gain speeding up the
log generation. This is recommended for systems that generate a large number of log events.
- YAML
- XML
- PHP
1 2 3 4 5 6 7 8
# app/config/config.yml
monolog:
use_microseconds: false
handlers:
applog:
type: stream
path: /var/log/symfony.log
level: error
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:monolog="http://symfony.com/schema/dic/monolog"
xsi:schemaLocation="http://symfony.com/schema/dic/services
http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/monolog
http://symfony.com/schema/dic/monolog/monolog-1.0.xsd">
<monolog:config use_microseconds="false">
<monolog:handler
name="applog"
type="stream"
path="/var/log/symfony.log"
level="error"
/>
</monolog:config>
</container>
1 2 3 4 5 6 7 8 9 10 11
// app/config/config.php
$container->loadFromExtension('monolog', array(
'use_microseconds' => false,
'handlers' => array(
'applog' => array(
'type' => 'stream',
'path' => '/var/log/symfony.log',
'level' => 'error',
),
),
));