PHP 7.3 reached end of support in December 2021 and Adobe Commerce 2.3.x reaches end of support in September 2022. You may want to consider planning your upgrade now to Adobe Commerce 2.4.x and PHP 7.4.x to help maintain PCI compliance.
Example—logging database activity
The following example shows how to log database activity using the Magento\Framework\DB\LoggerInterface
, which has two implementations:
- Logs nothing (default):
Magento\Framework\DB\Logger\Quiet
- Logs to the Magento
var/log
directory:Magento\Framework\DB\Logger\File
You can also use the Magento CLI to enable and disable database logging.
To change the default configuration of \Magento\Framework\DB\Logger\LoggerProxy
, edit your app/etc/di.xml
.
First, change the default values of loggerAlias
and logCallStack
arguments to:
1
2
3
4
5
6
7
8
<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>
After that, provide the file path for Magento\Framework\DB\Logger\File
:
1
2
3
4
5
<type name="Magento\Framework\DB\Logger\File">
<arguments>
<argument name="debugFile" xsi:type="string">log/db.log</argument>
</arguments>
</type>
Finally, compile the code with:
1
bin/magento setup:di:compile
and clean the cache with:
1
bin/magento cache:clean