We work on several Magento 2 projects on daily basis and that means constantly having to deal with code, database, errors etc. and one thing that comes in handy more often than we’d care to admit are the logs.

Logs when used correctly allow you to understand how your application works, what data is being passed, the errors, where they originate etc. This makes finding the issues and fixing them simpler if not easy.

In this article, I will explain how to enable database logging, which comes in handy especially when the data you expect to be read or written isn’t as you expected it to be. This happens quite often and can be really frustrating to debug.

To do this, we have to change the default configuration of \Magento\Framework\DB\Logger\LoggerProxy by editing the file app/etc/di.xml in your Magento 2 build.

Find <type name="Magento\Framework\DB\Logger\LoggerProxy">, there should be only one occurence of the search term. Replace the block with the one below.

<type name="Magento\Framework\DB\Logger\LoggerProxy">
    <arguments>
        <argument name="loggerAlias" xsi:type="const">Magento\Framework\DB\Logger\LoggerProxy::LOGGER_ALIAS_FILE</argument>
        <argument name="logAllQueries" xsi:type="init_parameter">Magento\Framework\Config\ConfigOptionsListConstants::CONFIG_PATH_DB_LOGGER_LOG_EVERYTHING</argument>
        <argument name="logQueryTime" xsi:type="init_parameter">Magento\Framework\Config\ConfigOptionsListConstants::CONFIG_PATH_DB_LOGGER_QUERY_TIME_THRESHOLD</argument>
        <argument name="logCallStack" xsi:type="boolean">false</argument>
    </arguments>
</type>

Next, add the following block of xml right below it:

<type name="Magento\Framework\DB\Logger\File">
    <arguments>
        <argument name="debugFile" xsi:type="string">log/db.log</argument>
    </arguments>
</type>
Live chat: cookie consent required

Copyright © Hungersoft 2019

· Terms & Conditions · Privacy policy