Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I use WP_DEBUG_LOG in my development environment and have no issues with debug.log being in the wp-content directory.

Sometimes I turn on WP_DEBUG in production when I need to debug something, and I still want to use the log but would like to redirect it to something outside my web root. Is this possible using WP_DEBUG_LOG?

share|improve this question

3 Answers 3

Afaik, you can't change the location for the default debug file. What you can change is the location for the MU error log as well as the location for the PHP error log file.

$ds = DIRECTORY_SEPARATOR;
# DEBUG
define( 'WP_DEBUG',               true );
// file: ~/WP_CONTENT_DIR/debug.log
define( 'WP_DEBUG_LOG',           true );
define( 'WP_DEBUG_DISPLAY',       true );
define( 'SAVEQUERIES',            true );
# DEBUG: MU
define( 'DIEONDBERROR',           true );
define( 'ERRORLOGFILE',           WP_CONTENT_DIR.$ds.'logs'.$ds.'mu_error.log' );

@ini_set( 'log_errors',           'On' );
# PHP Error log location
@ini_set( 'error_log',            WP_CONTENT_DIR.$ds.'logs'.$ds.'php_error.log' );
share|improve this answer
    
So I would need to turn off WP_DEBUG_LOG in order to make sure that the debug.log file is never created in my wp-content directory? –  jjeaton Feb 1 '13 at 19:59
1  
You're asking quite some questions for this day and time :) I'm not in the brain condition to answer those now. Come back tomorrow and jump in chat. –  kaiser Feb 1 '13 at 20:47

Yes, if you add some code to a plugin or a theme's functions.php like so:

if (defined('WP_DEBUG_LOG') && WP_DEBUG_LOG) {
    ini_set( 'error_log', WP_CONTENT_DIR . '/debug.txt' );
}

Edit: someone else just presented me with the need to do this, so I have dropped some code into a simple plugin they can edit; it's available as a gist if anyone wants it.

share|improve this answer
    
I tried adding this to my wp-config.php file and it doesn't work. Is that because wp-config.php is maybe loaded earlier than the actual place in the code where WP_DEBUG_LOG is used to define the log file? –  jjeaton Feb 2 '13 at 22:25
    
I was able to get this to work by adding it into a mu-plugin. Is there anyway for me to just make this change within wp-config? I'm assuming I'd just have to set WP_DEBUG_LOG to false and replace what it does myself? –  jjeaton Feb 2 '13 at 22:27
    
This works well if you can put the code in a plugin or theme, thanks! –  jjeaton Feb 2 '13 at 23:02
    
Yes, just dump it into a simple plugin. See Writing a plugin on codex. –  webaware Feb 2 '13 at 23:04
up vote 4 down vote accepted

It turns out that all WP_DEBUG_LOG does is:

ini_set( 'log_errors', 1 );
ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );

So, if you want to change the log location for WP_DEBUG_LOG in a plugin or theme, webaware's answer is best. If you just want to have it changed within wp-config.php you can replace define( 'WP_DEBUG_LOG', true ); with the above 2 lines and change the log file to wherever you want.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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