Enabling Magento Database Logging for exception.log and system.log
In Magento, logging can be configured both through the admin backend interface and directly via the database. While the admin configuration is straightforward, it may not always be accessible or desirable.
In this guide, we’ll walk you through how to enable both exception.log and system.log at the database level in your Magento installation.
Understanding the Configuration
Magento logging is controlled by several config settings in the core_config_data table. The most relevant for our purpose are:
dev/log/active: Enables log processing.dev/log/file: Specifies the log file name (default: logs/system.log).general/log/exception_enabled: Enables exception logging.
Step-by-Step Guide
-
Enable Log Processing
First, we need to enable log processing in Magento by setting the
dev/log/activeflag to 1. This ensures that the system can create and manage logs.UPDATE core_config_data SET value = '1' WHERE path = 'dev/log/active'; -
Specify Log File Name
By default, Magento uses
system.log. However, you might want to change this for better organization or compliance reasons. Update thedev/log/filevalue accordingly.UPDATE core_config_data SET value = 'path/to/your/custom_log_file.log' WHERE path = 'dev/log/file'; -
Enable Exception Logging
Magento’s exception logging is disabled by default. To enable it, update the
general/log/exception_enabledsetting to 1.UPDATE core_config_data SET value = '1' WHERE path = 'general/log/exception_enabled';
Additional Best Practices
-
Log Level: You can further control the level of detail in your logs by adjusting
dev/log/level. Valid options areemergency,alert,critical,error,warning, anddebug. -
Log Retention: Magento does not automatically manage old log files. Consider adding a cron job or script to periodically clean up and archive old logs.
Conclusion
Enabling database logging in Magento is a crucial step for monitoring your store’s performance, troubleshooting issues, and ensuring security compliance.
Remember that logging sensitive data should be handled with care, adhering to your organization’s privacy policies. Always review the content of your logs regularly to ensure nothing confidential is being exposed.
For more advanced logging and monitoring solutions in Magento, consider exploring third-party extensions or integrating with a dedicated log management service like ELK Stack for better analytics and real-time insights.