Magento 2 Enable Debug Log: Key Features

Magento 2 Enable Debug Log: Key Features

Want to find out the glitches in your Magento 2 store? Magento 2 enable debug log helps troubleshoot the debugging errors and enhance your store’s performance. This tutorial uncovers the key features of debug logs and the steps to enable them.

Key Takeaways

  • Discover how enabling debug logging in Magento 2 can enhance troubleshooting.

  • Learn step-by-step instructions for enabling debug logging through both GUI and CLI.

  • Understand the purpose and importance of debug logs in diagnosing software issues.

  • Explore key features of Magento 2 debug logging, including logging levels and configuration.

  • Gain insights into different types of logs in Magento 2 and their distinct purposes.

What are Magento Error Logs?

Magento error logs are records of errors, warnings, or other issues that occur within the Magento store. These logs help developers and administrators identify and troubleshoot problems within the system.

Magento logs various types of errors, including:

  • PHP errors

  • Database errors

  • JavaScript errors

  • Runtime issues.

What is the Magento 2 Debug Log?

Magento 2 debug log is a feature that allows developers to log detailed debugging information for troubleshooting purposes. This debug log captures various events, actions, and errors that occur within the Magento 2 system.

It helps developers to diagnose and troubleshoot issues within the application, including:

Debug logs typically contain information such as:

  • Debugging messages

  • Variable values

  • Function calls

  • Stack traces.

Key Features Magento 2 Debug Log

1. Purpose

The primary purpose of the Magento 2 debug log is to aid developers in diagnosing and resolving issues within Magento 2 installations. It provides detailed information about:

  • Flow of execution

  • The values of variables

  • Any errors or warnings that occur during runtime.

2. Configuration

Magento 2 debug log is not enabled by default. Developers can enable it by:

This allows developers to control the level of detail captured in the debug log and specifies which types of events should be logged.

3. Logging Levels

Magento 2 debug log supports different logging levels, such as:

  • Debug

  • Info

  • Notice

  • Warning

  • Error

  • Critical.

Developers can specify the desired logging level based on the severity of the events they want to capture. For example, setting the logging level to "debug" will capture all events, while setting it to "error" will only capture critical errors.

4. Location

The Magento 2 debug log is typically stored in the var/log directory within the Magento installation directory. Like other log files, it is organized by date and contains detailed information about each logged event, including:

  • Timestamps

  • Severity levels

  • Relevant context.

5. Debugging Process

Developers can review the debug log to gain insights into the flow of execution and identify any anomalies or errors. This can be done during troubleshooting issues within a Magento 2 installation.

The information captured in the debug log helps developers pinpoint the root cause of issues and implement appropriate fixes.

6. Security Considerations

Debug logs may contain sensitive information about the Magento installation. They should be handled with care and restrict access to authorized personnel only.

Developers should avoid logging sensitive data and ensure that debug logs are properly secured to prevent unauthorized access.

Difference Between Debug Log, Database Log, Cron Log, and Syslog Log

Aspect Debug Log Database Log Cron Log Syslog Log
Purpose Debugging and troubleshooting. They track operations and events related to database activity and performance. They record the execution of scheduled tasks (cron jobs) on a system. They capture system messages generated by the operating system.
Content They contain information such as debugging messages, variable values, and stack traces. They contain records of database transactions. It includes SQL queries, transaction start/end times, affected rows, and error messages. They contain entries for each cron job execution. They contain entries for various system events. Startup/shutdown messages, hardware/software errors, network activity, and security events.
Usage Diagnosing and troubleshooting software issues within the application. Monitor database activity, diagnose performance issues, troubleshoot errors, and ensure data integrity. Monitor scheduled tasks, verify their execution status, troubleshoot errors, and optimize scheduling. Monitor system health, diagnose hardware/software issues, track security incidents, and troubleshoot system errors.
Example Magento 2 debug log. MySQL general query log, error log, slow query log, and binary log. Cron logs are located in (e.g., /var/log/cron, /var/log/syslog). Syslog logs are located in (e.g., /var/log/syslog, /var/log/messages).

Steps to Enable Debug Log in Magento 2

Method 1: Through GUI

  1. Log in to the Magento Admin Panel.

Steps to Enable Debug Log in Magento 2-Log in

  1. Navigate to StoresConfiguration.

  2. Under Advanced, select Developer.

  3. In the Debug section, set Log to File YES.

  4. Save Configuration.

Steps to Enable Debug Log in Magento 2-Configuration

  1. Debug details are to be logged to debug.log.

Steps to Enable Debug Log in Magento 2-Debug

  1. If necessary, Flush the cache once.

Method 2: Through CLI Method

  1. Open your Magento Application Directory.

  2. Use the following command to enable debug logging for the current mode.

    bin/magento setup:config:set --enable-debug-logging=true
    
  3. Flush the cache using the command.

    bin/magento cache:flush
    

How to Disable Debug Log in Magento 2?

  1. Use the following command to disable debug logging for the current mode.
    bin/magento setup:config:set --enable-debug-logging=false
    
  2. Flush the cache using the command.
    bin/magento cache:flush
    

FAQs

1. What type of information is logged in the Magento 2.3.1 debug log?

The Magento 2.3.1 debug log records detailed information about various processes. It includes errors, warnings, debugging messages, and other relevant data. This information is invaluable for diagnosing and resolving issues.


2. Is there any specific code I need to add to enable debug logging?

Enabling debug logging doesn't typically require adding any additional code. It is usually done through the Magento Admin Panel or by modifying configuration files directly on the server. Follow Magento's best practices and back up your files before making any changes.


3. Can I enable debug logging while in production mode?

You can enable debug logging even if your store is in production mode. Debug logging can provide crucial insights into errors and issues, aiding in troubleshooting and improving performance.

Summary

Magento 2 enable debug log can help you understand what's wrong with your Magento store. It includes bugs, weird behavior, slow performance, and steps to fix them. This tutorial also covered several other points, including:

  • The debugging experience can be tailored by adjusting logging levels and specifying the types of events you want to capture.

  • The debug logs can be kept secure by being careful with sensitive info and limiting who can access them.

  • Understand the difference between debug logs and other types, including database, cron, and syslog logs, for their effective use.

  • Debug logs can be enabled and disabled through the convenience of the GUI or the directness of CLI commands.

Ready to optimize your Magento 2 store's performance and remove the bugs? Consider managed Magento hosting for a high-speed Magento store experience.

CTA

Ruby Agarwal
Ruby Agarwal
Technical Writer

Ruby is an experienced technical writer sharing well-researched Magento hosting insights. She likes to combine unique technical and marketing knowledge in her content.


Get the fastest Magento Hosting! Get Started