Log 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
var/log
directory:Magento\Framework\DB\Logger\File
TIP
You can use the Commerce 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:
<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
:
<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:
bin/magento setup:di:compile
And clean the cache with:
bin/magento cache:clean
recommendation-more-help
386822bd-e32c-40a8-81c2-ed90ad1e198c