When using PHP in your code snippets you’ll sometimes run into a fatal error. Luckily, WPCode comes with a built-in error catching functionality that will attempt to recover from most errors so that they don’t prevent you from accessing your site’s admin interface.
But even though the errors are caught you still need to find what caused them and how to fix them. This is where the error logging functionality comes in.
WPCode version 2.0.8 and higher includes an option to log errors thrown by snippets to help you identify issues. What’s more, the logs can be easily viewed from your site’s admin without having to use FTP or download any files.
How to enable Error Logging
Enabling error logging is done by toggling the Error Logging setting in the WPCode Settings menu in the WordPress admin of your site. Next, you just have to click the Save Changes button at the top and errors thrown by snippets will be logged moving forward.
Please note that if you enabled error logging after a snippet got automatically disabled you will have to enable that snippet again and wait for it to throw the error again for the error to be logged. With error logging disabled, no errors are logged in the WPCode logs but you might still find info in the server PHP logs if those are available.
Viewing error logs
Error logs can be seen from the Tools submenu of WPCode in the Logs tab. By default, the oldest log file will be loaded first but you can choose newer log files from the right hand dropdown menu and clicking the View button to switch to a different log.
Error logs are automatically split by days and if an error log exceeds a certain size for the day, WPCode will automatically create up to 10 other files for that day to avoid creating very large files.
Tips for using Error Logs
Error logs will point you to the reason for the fatal error but it’s up to you to fix the issue and that’s not always easy. A limitation of how we currently dynamically execute PHP snippets means that there’s no reliable way to indicate exactly which snippet threw an error but, if, for example the error is referencing an undefined function, that function’s name will be included in the error report logged. This is useful as you can then use the function name to search in the WPCode Snippets screen for that function as our search function takes the code into account.
After you fix the errors from your snippets we recommend deleting the logs.