One quick and common way to get debugging information about an application is to introduce some print tracing statements (print spam). If you run a debug environment as well as a production environment, you can set up a print statement for displaying this information that is defined differently in each of your environments.
I’ve got a configuration file for both dev and prod, and this file is responsible for defining the debugPrint statement. On dev, it looks like this:
function debugPrint($x) {
if (is_array($x)) {
echo ‘<p>’; print_r($x); echo ‘</p>’;
} else {
echo ‘<p>’ . $x . ‘</p>’;
}
}
And on prod, it looks like this:
function debugPrint($x) {
}
The nice thing about this simple addition is that I can litter questionable code with debug statements, and not worry about debug spam leaking through to production.
For me, the real benefit is being able to do things like this in the production environment:
function debugPrint($x) {
if (is_user_admin()) {
if (is_array($x)) {
echo ‘<p>’; print_r($x); echo ‘</p>’;
} else {
echo ‘<p>’ . $x . ‘</p>’;
}
}
}
Even in the production environment, it can be nice to have this debug information, but only if you’re the type of user who should be reading it. In this case, administrator users, or programmers, or whomever you’d like, are the only ones who see the debug spam.