Magento2: How to log all mysql queries?

Created on 19 Oct 2015  路  2Comments  路  Source: magento/magento2

Hi,

I want to log all mysql queries. I found the following file: lib/internal/Magento/Framework/DB/LoggerAbstract.php

I set in the constructor: $logAllQueries = true
However, I do not see any additional files in var/log after logging into the backend.

Could you tell me how to check these queries?

In advance, thank you.

Ready for Work

Most helpful comment

Hi @tommyJS ,
you should not need to use or change the LoggerAbstract.
Magento relies on \Magento\Framework\DB\LoggerInterface for logging and has two implementations out of the box: \Magento\Framework\DB\Logger\Quiet (default one, logs nothing) and \Magento\Framework\DB\Logger\File (really logs something).
To enable logging, change preference for Magento\Framework\DB\LoggerInterface to \Magento\Framework\DB\Logger\File in app/etc/di.xml (search for Magento\Framework\DB\LoggerInterface in the file - it should have preference to Quiet, which you need to change):

<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>

See also constructor of Magento\Framework\DB\Logger\File to find what can be configured and what are default values. You can configure necessary values in the same di.xml. For example,

<type name="Magento\Framework\DB\Logger\File">
    <arguments>
        <argument name="logAllQueries" xsi:type="boolean">true</argument>
        <argument name="debugFile" xsi:type="string">my.log</argument>
    </arguments>
</type>

All 2 comments

Hi @tommyJS ,
you should not need to use or change the LoggerAbstract.
Magento relies on \Magento\Framework\DB\LoggerInterface for logging and has two implementations out of the box: \Magento\Framework\DB\Logger\Quiet (default one, logs nothing) and \Magento\Framework\DB\Logger\File (really logs something).
To enable logging, change preference for Magento\Framework\DB\LoggerInterface to \Magento\Framework\DB\Logger\File in app/etc/di.xml (search for Magento\Framework\DB\LoggerInterface in the file - it should have preference to Quiet, which you need to change):

<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>

See also constructor of Magento\Framework\DB\Logger\File to find what can be configured and what are default values. You can configure necessary values in the same di.xml. For example,

<type name="Magento\Framework\DB\Logger\File">
    <arguments>
        <argument name="logAllQueries" xsi:type="boolean">true</argument>
        <argument name="debugFile" xsi:type="string">my.log</argument>
    </arguments>
</type>

Hi @buskamuza ,

thank you for the quick answer.
It works ;)

Was this page helpful?
0 / 5 - 0 ratings