When it comes to working with WordPress, the Codex does a good job of showing how to configure the application for debugging.

In short, you add the following to your wp-config.php:

// Enable WP_DEBUG mode
define( 'WP_DEBUG', true );

// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );

// Disable display of errors and warnings
define( 'WP_DEBUG_DISPLAY', false );
@ini_set( 'display_errors', 0 );

There’s more you can add, but this is the general idea as to what I find useful.

But why bother covering this?

WordPress Debug Logs

Sometimes the advantages of having a debug log seem obvious. Other times, though, it may not always be evident as to why it’s helpful.

We’ve all heard the excuse (to the point where it’s a joke, really):

It works on my machine.

But we really shouldn’t be defaulting to that. It passes the buck, it’s dismissive, and it’s not how we should be operating.

A Debugging Quick Tip

That said, this is more or less a quick tip as to the how and why you should have one set up between your development and staging environments.

WordPress Debug Logs

 

First, whenever you have debugging setup, it will generate a debug.log file that you can review whenever you’re working in your development environment.

The benefits of this are usually obvious:

  1. you can refer PHP notices, warnings, and errors on your machine,
  2. you see the file and line on which the problem is occurring,
  3. you get the timestamp of when the problem occurs

So what though, right? I mean, this is something that we should be doing with every local project.

But in your staging environment, I think it’s also important to make sure debugging is turned on. You can have nearly every single thing configured the same but if even one thing is different, then the software may not work the same way.

And this is where and why having debugging setup the same on staging matters. You can often find where the discrepancies that exist.

If they exist your code, then there’s a responsibility to resolve them. Otherwise, it will at least reveal where the problems are with the environment – be it the server or third-party software.