Dump debug output to file

Here's a little addon that will dump the debug output to a file. You could spruce this up by having it email the webmaster I suppose. I use it by keeping the debug output silent ($db->debug_echo_is_on = false;) and then creating the file instead.

First, you'll need to add two (2) variables to the core file:

var $debug_dump = false;
var $debug_dir = null;

It will be off by default. Then, on the debug() function, you'll need to add the following code anywhere after the $html = ob_get_contents();, because that's the information that's going to be written to the file.

// Write output to debug file
if($this->debug_dump) {
    $debug_file = $this->debug_dir.'/'.date('d-m-Y-h-i-a');

    if(!is_dir($this->debug_dir)) {
        $this->show_errors ? trigger_error("Could not open debug dir: $this->debug_dir", E_USER_WARNING) : null;
    } else {
        error_log($html, 3, $debug_file);
    }
}

And finally, and example of how to use this:

// Turn on debug dump
$db->debug_dir = 'debug';
$db->debug_dump = true;

Make sure you're debug directory has the correct permissions, it should be setup just like the cache directory. The filename will output like so:

10-11-2006-07-58-pm

It would probably make more sense to have a stripped down version of the debug output, instead of it being jazzed up with HTML. And this wouldn't be a bad idea for the error reporting too.