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.
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:
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:
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!
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:[pastacode lang="php" manual="function%20zpd_change_error_log()%20%7B%0A%20%20ini_set(%20'error_log'%2C%20ABSPATH%20.%20'%2F~%24debug.log'%20)%3B%0A%7D%0Aadd_action(%20'init'%2C%20'zpd_change_error_log'%2C%2010%20)%3B" message="" highlight="" provider="manual"/]
You can go ahead and change the function name in lines 1 and 4 to something other than [codelet]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.