How to Disable Microseconds Precision (for a Performance Boost)

How to Disable Microseconds Precision (for a Performance Boost)

New in version 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
    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
    
  • XML
     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>
    
  • PHP
     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',
            ),
        ),
    ));
    

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.