Tag Archives: debugging

WordPress Logging to File

I’ve been doing some Ajax development so wanted to log any errors to a file rather than screen, this is because any messages written into the return from the Ajax call can corrupt the message and the Javascript calling the function cannot interpret the data.

Logging to file could also be useful when debugging very visual things (where you don’t want extra messages) such as themes. Also background scheduled cron jobs are the same as Ajax calls and run with no user interface so you need to send the messages to file not to the screen.

Although it is possible to configure the logging modes yourself via php.ini or .htaccess, WordPress sets up some constants in the WP_CONFIG.php file which make it simpler to setup debug logging to file.

the wp-config.php file
wp-config.php

The setting first is the master control for debugging.

define('WP_DEBUG', true);

Without this setting nothing will get logged.
The next setting is

define('WP_DEBUG_LOG', true);

This tells WordPress to log everything to the /wp-content/debug.log file, if you want to log to an alternative location do not include this setting and use the settings described in the first reference below.Finally we need to turn off the display of setting to the user (or Ajax call) using the following setting

 define('WP_DEBUG_DISPLAY', false);

if you set these three settings then you should have logging to file. It’s worth turning this off once your debugging session has finished as the file can get quite large quite quickly.
Further reference

http://digwp.com/2009/07/monitor-php-errors-wordpress/
http://codex.wordpress.org/Debugging_in_WordPress
http://digwp.com/2009/07/monitor-php-errors-wordpress/