Magento error logs: Simple guide for you to maintain your site and keep it healthy

Magento error logs are a tool that lets you do basic troubleshooting and understanding the essence of your issues especially when you’re seeing that something is going wrong, but you have no idea what exactly is not OK. Magento allows showing the error message in various forms based on its server settings whether it is in developer mode or in production mode. If you are busy debugging any type of issue on your Magento 2 store then it better is to set it in developer mode to not face any type of inconvenience.

Magento Error Logs Overview

Magento Error Logs

You probably know that when a user requests any website pages, the request is solved by several apps:  first of all, it’s a web-server, which communicates with the Magento PHP application.  Magento in its turn sends queries to the database. Commonly, during this process, things can go the wrong way.  Then the responsible app writes the error and corresponding information into a special file called the error log. Monitoring these log files allows you to find and solve possible problems you may not be aware of for a long time.

If you are having a problem in which your Magento website shows a plain white page, a blank page with the error numbers, 500 Internal servers, or any broken content error with a missing footer then to handle this problem apply the below-given steps on your Magento 2 Store  to debug your Magento store

Enable error reporting to check the blank white page

If there is a blank white page error on your web page, then this is a serious PHP error that can’t be recovered. So, for security reasons server tends to be configured by default to hide the error message as it relates to sensitive information. The most effective and smoothest method of debugging a blank page error is to know the root of the issues that created it.

Step 1: Check your apache or PHP errors and for that, connect your server with FTP, or SSH. Now either connect with your hosting provider and raise a ticket to access your Magento error logs files or utilize the cPanel file manager.

Step 2: If you are facing an issue exploring the location of your error log files, you can forcefully print the below command to your browser by editing your index.php file as shown below:

error_reporting(E_ALL);
ini_set('display_errors', 1);

Eg. index.php

 ...
error_reporting(E_ALL);
ini_set('display_errors', 1);
try {
require DIR .'/app/bootstrap.php';
} catch (\Exception $e) { ...... }

If you don’t want your visitors to see the sensitive information, you can easily hard code your IP address to the only showcase error message on your IP address. How you can do it is tailored below, use the below command coding, and safeguard your information.

$customIPAddress = ['your IP address here'];
if (in_array($_SERVER["REMOTE_ADDR"], $customIPAddress) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
}

After enabling error reporting

After enabling error reporting, it displays a blank white page with information sensitive error message. To track the error shown, you can effortlessly visit the SSH server and drag your cursor to the var/folder/report of Magento, learn the name of the file and read the error message easily. This will help your work easier and smoother.

Enable error reporting to rectify a broken content error

The not working content error with the missing footer happens mostly when PHP encounters an error while outputting the page content that prevents PHP from working. To determine and fix the error, press Ctrl+U to browse through the page source, then scroll through the page’s bottom and check there is any error information or message. If you can’t find any error, then enable the error reporting, and take it a shot again!

Enable Magento Error Logs

  1. Go to Log in to the admin panel
  2. Move to System > Configuration > Advanced > Developer
  3. Enable the option of Log Settings
  4. Save
Magento error logs

Attention: Grant the full permission, i.e., 777 to the folder /var/log where log files are stored.

Method to Find the Magento Error Log File

Find the Magento Error Log File

 We have the logging enabled and now it is time to learn how to find that file too!

The log files are placed  in the <magento-folder>/var/log/ folder.

If you do not find the log files here, track if the folder is given the writing permission. If not, the web servers won’t be able to generate the log files.

The original files are system.log with all PHP warnings and issues with XML files and exception.log with all the special cases when Magento fails to solve data for any reason.

However, a few important takeaways. Ensure the errors are hidden in the production model. Do check the Apache logs as well. If you are a Magento 2 store owner, the entire process becomes easy for you! Just using a single command:

php bin/magento config:set dev/debug/debug_logging

Get Notifications About Magento Errors

And here í the helpful tip we promised to teach you. If the website is up and running, and there are no errors in the logs, then you can simply set up a cron job in Magento to send you a message if the files are not empty (and then remove the file).

You get a message each time there’s a new record in your Magento error logs. This is a simple way to start method, but we suggest going further and using any kind of tool to receive Magento error reports.

Conclusion

By following the above-given steps, you will well enable the error reporting in Magento 2. If you find any difficulties in following the above-given Magento error logs steps then you can feel free to contact our Support Team who will guide you regarding this. We provide a Magento Website Development service that definitely will help you solve this problem.