How to Rename the WordPress Debug Log

Renaming the WordPress debug log file is super easy. You can modify it in the configuration file or your theme functions file. Here’s how.

When you turn on WordPress debugging to a log file, the default file it creates is /wp-content/debug.log .

This is probably fine for a single local development machine.

Sometimes it is necessary to turn on WordPress debugging on production servers to investigate issues.

You don’t really want that log file being exposed publicly on dev, staging and certainly not production servers.

There are a couple of ways to change the debug log file name and path.

Modify wp-config.php

When you turn WordPress log debugging using define( ‘WP_DEBUG_LOG’, true); the WordPress core runs code in the file wp-includes/load.php . Here’s the relevant code:

function wp_debug_mode() {
    if ( WP_DEBUG ) {
        error_reporting( E_ALL );

        if ( WP_DEBUG_DISPLAY )
            ini_set( 'display_errors', 1 );
        elseif ( null !== WP_DEBUG_DISPLAY )
            ini_set( 'display_errors', 0 );

        if ( WP_DEBUG_LOG ) {
            ini_set( 'log_errors', 1 );
            ini_set( 'error_log', WP_CONTENT_DIR . '/debug.log' );
    } else {
    if ( defined( 'XMLRPC_REQUEST' ) )
        ini_set( 'display_errors', 0 );

You can see the debug logging code in lines 10-13.

It sets two PHP ini_set declarations.

Line 11 tells PHP to start logging to a file.

Line 12 tells PHP which file name and path to write the log to.

You can change the file name and path using the following code in your wp-config.php file:

define( 'WP_DEBUG_LOG', false );
ini_set( 'log_errors', 1 );
ini_set( 'error_log', dirname(__FILE__)  . '/~$debug.log' );

Line 1 sets WP_DEBUB_LOG to false so that WordPress doesn’t run the core code we look at previously (setting the default log file name and path).

Line 2 tells PHP to start logging to a file (of course we need this to happen).

Line 3 allows us to specify our own file name and path.

In this example I am creating a file called ~$debug.log in the same folder as the config file, usually the WordPress root folder.

Syncing Using Dropbox

You may be asking why use ~$ at the beginning of the file?

Using multiple computers during the week, desktop and laptops, I need a way of synchronising my project files and Dropbox provides that mechanism for me.

However, I don’t want huge debug log files being synced especially when issues are likely to be machine software specific (think of different PHP versions or loaded modules).

Using the ~$ symbols at the beginning of a file tells Dropbox that it is a temporary file and not to sync it. Perfect!

Modify functions.php

Sometimes you don’t want to, or simply can’t edit the wp-config.php file.

So the only other alternative you have is to modify your theme’s (or child theme’s) functions.php[/codelt] file.

This is a neater way of changing the debug filename and file path and it means that if you move your site to another server, you don’t have to duplicate all the stuff in the configuration file. It will just work.

Add the following lines to the bottom of your functions.php file:

function zpd_change_error_log() {
  ini_set( 'error_log', ABSPATH . '/~$debug.log' );
add_action( 'init', 'zpd_change_error_log', 10 );

You can go ahead and change the function name in lines 1 and 4 to something other than zpd_change_error_log.

The constant ABSPATH is a WordPress defined constant specifying the root path of your installation.


And there we have it. Two ways to change the file name and path of your WordPress debug log.

Was this article helpful?

Keep In Touch With My Weekly Blog Email

A once-per-week daily digest of my posts from the week. No sales, no spam and I will not share your details with anyone else.


Wil is a dad, WordPress consultant, WordPress developer, business coach and mentor. He co-organizes the WordPress Sydney meetup group and has been on the organising committee for WordCamp Sydney since 2014. He speaks at many special events and contributes to the WordPress open source project. His likes are chillies, craft beer and electrogravitics.