Skip to content
Home » News » Magento 2 Log Management – A Simple Guide

Magento 2 Log Management – A Simple Guide

Is your Magento 2 store showing errors that are hard to trace? Magento 2 log management is a useful tool for identifying and fixing these problems quickly. This guide will explain the different types of Magento log files, how to access them, and how to secure them from unauthorized access.

Why Magento 2 Log Management Matters

Log files are like the black box of your store. They record everything that’s happening—errors, system activities, user actions, and more.

Key Benefits of Log Management:

  • Improves performance by identifying what slows down your site.
  • Boosts security by allowing you to catch unusual activities early. 
  • Saves time by enabling faster issue resolution through detailed error tracking
  • Keeps operations smooth by preventing crashes and downtime.
  • Helps developers in debugging code efficiently.
  • Supports compliance by keeping records of all changes and actions.
  • Enhances customer experience by ensuring fewer bugs, which means happier customers.

What Are Magento 2 Log Files?

Magento 2 log files store details about your store’s activities and errors, helping to track events and pinpoint issues for easier resolution. You can access these files on your server using FTP, SSH, or through your hosting panel.

Types of Magento Error Logs

Here are the main log files used in Magento 2:

  1. Exception Log: Tracks serious errors that actually break the system.
  2. System Log: Records general system warnings and issues.
  3. Debug Log: Offers detailed technical info for developers.
  4. Cron Log: Shows the status of scheduled tasks (like emails or backups).
  5. Database Log: Tracks database errors and slow queries.
  6. Admin Log: Logs admin actions such as product edits or settings changes.
  7. Security Log: Captures failed logins or other suspicious activity.
  8. Web Server Log (Apache/Nginx): Logs all requests and errors from users.
  9. PHP Error Log: Reports issues with PHP code running your store.

Default Magento 2 Logging Settings

By default, Magento logs are stored in /var/log/. Here’s what you should know:

  • Exception and system logs are automatically enabled.
  • Debug logs only work when the system is in developer mode.
  • Magento doesn’t remove old logs automatically, so using tools like logrotate will help manage them and keep the storage organized. 
  • Errors are hidden from customers in production mode for security.

Use this command to enable developer mode for more detailed logs:

php bin/magento deploy:mode:set developer

Custom Logging in Magento 2

Magento allows creating your own logs if you would like to track specific things.

Here are some options you can use:

  • Create new log files for some modules or functionalities. 
  • Apply different log levels such as debug, info, warning, or error to organize your logs.
  • Keep a record of customer actions, product modifications, or updates to orders.
  • Monitor interactions with the database and spot any slow queries to enhance performance
  • Record cron jobs, which are scheduled automated tasks, to make sure they’re running smoothly. 
  • Transfer your logs to external systems using syslog for storage outside Magento.
  • Generate log files for specific events, like tracking failed payment attempts, to quickly address issues. 

How to Access Magento 2 Logs

1. Through the Admin Panel:

  • Go to Stores > Configuration > Advanced > Developer > Debug.
  • Set “Log to File” to Yes.
Developer -> debug section in Magento admin

NB: In newer versions of Magento 2, especially starting from Magento 2.4.x and beyond, the “Log to File” option under Stores > Configuration > Advanced > Developer > Debug is no longer available or relevant in recent versions. Instead, all detailed logs — such as system, exception, debug, and others — are stored in your Magento file system, specifically in /var/log/. You need to access these logs directly on the server using:

  • SSH (command line)
  • FTP or File Manager (cPanel, Plesk, etc.)
  • Or a third-party extension

2. Through the Server (Recommended):

  • Use FTP or SSH to go to the /var/log/ directory.
  • View or download files like system.log, exception.log, or debug.log.

3. Using Command Line:

tail -f /path/to/magento2/var/log/exception.log
  • Use this to view logs in real time.

4. In Production Mode:

  • Errors aren’t shown on the frontend, but logs are still written to files.

5. Email Alerts (Optional):

  • Go to Stores > Configuration > Advanced > System.
  • Set up email alerts for errors and warnings. Under Mail Sending Settings section, turn on Email Notifications for errors, warnings, and system events.

NB: In newer versions of Magento 2, especially 2.4.x and above, the “Error Emails” section under System > Mail Sending Settings has been removed or deprecated from the Admin Panel. In new versions, Magento no longer has a built-in GUI option to send error log notifications via email like it did in earlier versions. This means if you want to receive error or system log alerts by email, you’ll need to set it up manually or use an extension.

How to Protect Magento Log Files

  1. Set File Permissions:  Ensure that only administrators can access and view log files. This limits exposure to sensitive information. 
  1. Move Logs Outside Web Root: Relocate log files so they’re not accessible from the public internet. This provides an extra layer of security.
  2. Use Server Rules: Implement rules in your Nginx or Apache server configuration to block unauthorized users from accessing the log files.
  3. Restrict User Roles: Ensure that only admin-level users have permission to view logs. Regular employees or general users should not have log access.
  4. Enable Log Rotation: Regularly manage and clean log files to prevent them from becoming too large and unmanageable.
  5. Use HTTPS: Secure the admin panel with HTTPS to encrypt data during transmission, which helps secure the logs as admins access them.
  1. Install Security Extensions: Add tools to monitor and alert you about log file activities and potential threats.
  2. Watch for Suspicious Activity: Set up alerts to notify you of events like failed login attempts or other unusual access efforts.
  3. Encrypt Sensitive Data: Apply encryption to sensitive log data for additional protection against unauthorized access.
  4. Keep Magento Updated:  Regularly update your Magento software to patch security vulnerabilities and protect your log files.

Conclusion

Magento 2 Log management is crucial for making sure your store stays safe, fast, and consistent. Logs are very helpful for solving problems, improving store performance, and protecting against security risks. They provide important information to quickly find and fix problems, which helps minimize downtime and ensures everything runs smoothly. By monitoring any strange or suspicious activities, logs significantly improve your store’s security. Effective log management also ensures that your store operates consistently and helps meet compliance requirements and accountability standards. Custom logging lets you choose which events and actions to track, giving you more control over your data. It’s equally important to secure these log files to prevent unauthorized access. Overall, proper log management is essential for operating a successful and resilient Magento 2 store.

Author

Leave a Reply

Your email address will not be published. Required fields are marked *