How to get Doctrine to log queries in Symfony2

后端 未结 2 1593
半阙折子戏
半阙折子戏 2021-02-20 15:15

I\'m pretty new to Symfony2, and I\'m looking for a way to log SQL queries (including timings) to the same log file as the rest of my application.

From what I can determ

相关标签:
2条回答
  • 2021-02-20 15:39

    Full example of config:

    config/packages/dev/doctrine.yaml:

    doctrine:
        dbal:
            connections:
                default:
                    logging: true
    

    If you still don't have monolog, install it: composer require symfony/monolog-bundle and you should start getting all SQL queries in the log file: var/log/dev.log

    0 讨论(0)
  • 2021-02-20 15:54

    If you are really sure that you need to log doctrine 2 queries in production then you can set this up in the configs for doctrine.

    connections:
            # A collection of different named connections (e.g. default, conn2, etc)
            default:
                    # when true, queries are logged to a "doctrine" monolog channel
                logging: true 
    

    http://symfony.com/doc/current/reference/configuration/doctrine.html

    And config monolog to log doctrine like explained in the docs: http://symfony.com/doc/current/cookbook/logging/channels_handlers.html

    A similar issue can be found at symfony 2.4 can't get the doctrine channel in prod environment

    0 讨论(0)
提交回复
热议问题