Is there a way to write the debugging I do in my code (ex: error_log("$msg"); to a different log file than the rest of the system-generated logging that gets written to /wp-content/debug.log?

I would settle for being able to show only my debugging along with fatal errors and parse errors all in the same file, but setting:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set('display_errors', ~E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED & ~E_NOTICE);

does not seem to do the trick.

Any suggestions?

1 Answer 1


You can tell error_log() where to put its output:

error_log( 'my debugging output', 3, '/my/debug/log/location/log.txt' );

It might be more convenient to add your own function:

if ( ! function_exists( 'my_debug' ) ) {

  function my_debug( $x = '' ) {
    // Uses print_r() in case $x isn't a string.
    error_log( print_r( $x, 1 ), 3, '/my/debug/log/location/log.txt' );


// ... elsewhere

my_debug( $the_variable_i_want_to_check );

  • 1
    Awesome - thanks!! I also added date('Y-m-d H:i:s') to the beginning of x so the date and time are captured and "\n" to the end so that each entry is displayed on a new line.
    – Daveh0
    Commented Feb 14 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.