Review our 2.2 release candidate! This beta version documentation includes B2B and more. See the Quickstart Guide
Stay tuned — We'll roll out more 2.2 documentation updates in the coming weeks.

Example—logging database activity

Example—logging database activity

To log database activity, use Magento\Framework\DB\LoggerInterface, which has two implementations:

To change the preference to \Magento\Framework\DB\Logger\File, edit your app/etc/di.xml.

First, change the default preference

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

to

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

After that, add the following block to configure file-based logging:

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