Share

Send values of variables to a debug file with a simple function call.

When developing a plugin or function, its often useful to be able to read variables at critical points in your code. Or, to log important events over a number of days.

Calling this function, allows you to send variables or messages into a text file in your uploads folder. Every message sent to this debug file is timestamped and added to the top of the file. Once the file becomes very large, it is automatically trimmed.

The Code

Usage

It’s very simple to use. There are several examples below. Note, that you must serialize arrays.

To read the debug file, you can view it in your browser, as can anyone else. Please don’t store any sensitive data in the file! Point your browser at – ‘<YOUR URL>/wp-content/uploads/debug.txt’.

<?php

add_to_debug('Some code section ran');
if ($condition === true) add_to_debug('Something occurred message');
add_to_debug($string);
add_to_debug($array);
 

Share