How to make sense of your OpenCart error log
The error log is the place to go when you want to know whether your store is working as expected or there are some cases when an error happens and your customers may not be getting the desired experience. The error messages there can help your site developers track down a bug or fix an issue you never actually experienced. Let’s see how to make use of it and help you and your developers maintain the system in good health.
Configuration
In OpenCart, you can configure how the errors are being handled by the system. This can be done by going to System > Settings > Edit > Server and configuring the “Display Errors” and “Log Errors” options. We would suggest keeping the “Log Errors” option enabled at all times. If you are currently developing your site, then it is recommended to enable the “Display Errors” options as well, otherwise keep this one disabled.
The physical file and its size
Physically, in the filesystem, the error log file path is system/logs/error.log and normally its size ranges from several KiloBytes to 1-2 MegaBytes. OpenCart’s web viewer just prints the contents of this file to you. However, there are cases when this file becomes very big (measured in MegaBytes), and then the chances are that you will have issues opening the web viewer. If that happens, you should manually go and backup the error log (by just renaming it), so OpenCart can start logging in a new file. If the file size grows rapidly in a short period of time, this is a sign that there is a frequently occurring error which should be fixed urgently.
The format
In OpenCart every error logged though the Log library(system/library/log.php) follows the same simple pattern and that is “date - error_message”, where date is the date time saved to the second and error_message is the actual error. Most of the errors are descriptive enough for you to understand what part of the system is causing the problems and contact the respective developer if it is from an extension, or give more initial information to your site developer. For example the error: “PHP Notice: Undefined variable: variable in system/modification/admin/view/template/common/menu.tpl on line 163” has obviously happened in the admin panel’s menu.
Protect your error log
Sadly, by default the error logs in OpenCart are publicly available and you must do extra work to protect them. This is important because the errors usually expose the full filesystem path to PHP files, which gives information about your operating system and username. Fortunately, if your server is Apache, it is quite easy to lock your error logs by adding an .htaccess file in the system/logs/ directory. The file’s contents should be just “Deny from all” (without the quotes). To test if you are vulnerable just try opening your site and append the following to the URL “/system/logs/error.log” (again without quotes). If you see your error log, then you are vulnerable. Now add the .htaccess file and try again. You should see “Forbidden” now.
Give yourself super powers
Reading the raw logs, you may find it hard to distinguish between the different error messages or get additional useful information like the number of times an error has appeared for example. Do not worry, we have you covered. We created a module called Error Log Manager, which organizes the errors and gives you a nice listing with only the unique error messages. The module works with any file sizes (we have tested it with files as big as 250MB), and have some neat features like quick code preview and filters by date. It also counts how many times has each error occured. You can take a look here https://isenselabs.com/products/view/errorlog-manager-multiple-error-log-files-manager
Hope this article will help you keep a healthier system!