data/dbal_log_time

Replacement for symfony's dbal logger, logging execution time

1.1.0 2022-01-13 12:11 UTC

This package is auto-updated.

Last update: 2024-11-14 20:01:49 UTC


README

This module provides a class to extends DBAL logging with execution time

Install

composer require data/dbal_log_time

Activation

In services.yaml, add :

services:
    doctrine.dbal.logger:
        class: 'Data\DbalLogTime\DbalLogger'
        tags:
            - name: "monolog.logger"
              channel: "doctrine"
        arguments:
            - "@logger"
            - "@debug.stopwatch"

Then you can configure logging as usual, for example :

# config/packages/prod/monolog.yaml
monolog:
    handlers:
        db:
            channels: doctrine
            type:     stream
            level:    debug
            path:     '%kernel.logs_dir%/doctrine.log'
# config/packages/prod/doctrine.yaml
doctrine:
    dbal:
        connections:
            default:
                logging: true

Details

There are 2 classes you may use :

  • Data\DbalLogTime\DbalLogger extends the default dbal logger, adding an addtitionnal log line at the end of the query, which displays the execution time
  • Data\DbalLogTime\Params\DbalLogger re-implements the logger to add the execution time in a _duration element in the parameters array. The query is therefore logged after it was executed