Understanding WordPress Error Logs – Locating And Reading Debug.Log

Locating the debug.log File

The debug.log file records errors, warnings, notices and other diagnostic information from WordPress. Knowing where this file is located on your particular hosting environment is key to effective troubleshooting.

Typical locations of debug.log on different hosting environments

The debug.log file is usually found in the /wp-content/ folder of your WordPress installation. However, the exact location depends on your hosting environment:

  • Shared hosting – /wp-content/debug.log
  • VPS or dedicated server – /path/to/site/wp-content/debug.log
  • Local MAMP/WAMP install – /path/to/project/wp-content/debug.log

Using FTP to find debug.log

If you are unsure of the location, use FTP to browse the wp-content folder and check for the debug.log file. Sometimes it is nested in additional subfolders like /wp-content/uploads/ or /wp-content/advanced-cache/.

Enabling debugging in wp-config.php

To start logging errors, warnings and notices to debug.log, you need to enable debugging in WordPress. Add the following lines to your wp-config.php file which is found in your site’s root folder:

define( 'WP_DEBUG_LOG', true );  
define( 'WP_DEBUG_DISPLAY', false );

This will keep the front-end working normally while logging information to debug.log behind the scenes.

Reading and Interpreting the Contents

The debug.log contains detailed diagnostic entries that provide hints for troubleshooting WordPress problems:

Layout and format of log entries

A typical debug.log entry contains:

  • Timestamp – Date and time the issue occurred
  • Log level – Severity level e.g. DEBUG, INFO, WARNING, ERROR
  • Origin – Source code file and line number
  • Message – Details of the issue being logged

Key pieces of information in each log entry

Some key details to pay attention to are:

  • Timestamp – Can help identify sequence or timing correlation between issues
  • Log level – Gives insight into severity, errors are more urgent than warnings or debug messages
  • Origin – Reveals the source plugin, theme or core code triggering issue
  • Message – Provides context and description around logged issue

Meaning of different error levels and codes

Understanding the different log levels helps gauge severity:

  • DEBUG – Detailed debug information
  • INFO – Helpful workflow information
  • NOTICE – Normal operation that merits attention
  • WARNING – Indicates a problem that requires investigation
  • ERROR – Critical issue affecting functionality
  • CRITICAL – Prevents site from running entirely

HTTP response codes in messages also indicate specific issues:

  • 500 errors – server-side issues
  • 404 errors – file or page not found
  • 403 errors – file permission problems

Real-World Examples

Seeing actual debug.log examples helps read and interpret entries. Common issues include:

Example log for a fatal error on plugin load

[10-Dec-2023 15:27:41] ERROR Plugin A could not be initialized 
[10-Dec-2023 15:27:41] ERROR Plugin A missing required function plugin_a_init
[10-Dec-2023 15:27:41] FATAL Fatal error: Call to undefined function plugin_a_init() in /htdocs/wp-content/plugins/plugin-a/plugin-a.php on line 23

This shows a fatal crash preventing the plugin ‘Plugin A’ from running at all. The hint is the missing plugin_a_init function on line 23.

Example log for a database connectivity issue

[11-Dec-2023 09:18:32] ERROR Database connection lost 
[11-Dec-2023 09:18:32] WARNING Reconnecting to database 
[11-Dec-2023 09:18:37] INFO Database connection reestablished

The site lost then regained connectivity to the database. Temporary availability issues like this can lead to visible problems for site visitors.

Example log for a file permission error

 
[15-Dec-2023 12:45:18] ERROR Unable to write to wp-content/cache (Permission denied)

Permission errors like this one often occur after migrations. The file owner or permissions need to be adjusted.

Fixing Common Issues

Armed with clues from debug.log, many problems are quick fixes. Try:

File permission errors

Use FTP or SFTP to update permissions to 755 for folders, 644 for files. Check ownership is correct user account.

Plugin conflicts

Try disabling suspect plugins one-by-one. If issue disappears when a plugin is disabled, that plugin needs further configuration or isolation.

Database connectivity problems

Contact hosting support. For site migrations, double check database credentials match the new server.

Memory limit errors

Increase PHP memory allocation in wp-config.php or php.ini. A good starting point is 256M.

Improving Troubleshooting with Debug Mode

More extensive debugging helps tackle trickier WordPress issues:

Enabling WordPress debug mode

Add the following constant definition to wp-config.php:

  
define( 'WP_DEBUG', true );

This displays errors and warnings on the page instead of just logging them behind the scenes.

Using debug mode to log additional details

There are different debug logging levels from 1 (default) to 9 (maximum logging). Change via:

define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);  
define('WP_DEBUG', 9);

The higher the setting, the more context will be captured on bugs and crashes.

Extra debugging tools to enable

These further debugging plugins and tools are helpful for detailed troubleshooting:

  • Debug Bar
  • Query Monitor
  • PHP error logging
  • Xdebug

Leave a Reply

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