Log database activity
Last update: May 16, 2023
- Topics:
- Configuration
- Logs
- Storage
CREATED FOR:
- Experienced
- Admin
- Developer
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
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
Previous pageLogger interface
Next pageWrite to a custom log file
Commerce
- Overview
- General setup
- Deployment
- Cache
- Command Line
- Command-line tool
- Common commands
- Enable logging
- Manage the cache
- Manage indexers
- Configure cron jobs
- Compile code
- Operation mode
- Start message queue consumers
- URN highlighter
- Dependency reports
- Localization
- Configuration management
- Static view
- Create symlinks
- Run unit tests
- Convert layout files
- Generate data for performance testing
- Run support utilities (Commerce only)
- Configuration files
- Configuration paths
- Cron Jobs
- Logs
- Message Queues
- Multiple sites
- Search Engine
- Security
- Storage
- Return to Operational Guides