Debugging ActiveTable

ActiveTable has the capability to output a ton of useful debugging information, using either PEAR::Log or just printing to the user's screen. Two attributes control logging, debug and logfile_path.

Generally, you would want to utilize the debug logs if you want to see the queries ActiveTable is generating for you (if, for example, you're getting an invalid query generated) or if you'd like to see the performance of a certain query.

Use

To have it log to a file:

<?php
class Foo extends ActiveTable
{
    protected $table_name = 'foo';
    protected $primary_key = 'foo_id';

    protected $debug = true; // Defaults to false
    protected $logfile_path = '/tmp/active_table.log'; // This is the default value
} // end Foo class
To have your log messages outputted to the screen, set logfile_path to null instead of setting a path:
<?php
class Foo extends ActiveTable
{
    protected $table_name = 'foo';
    protected $primary_key = 'foo_id';

    protected $debug = true; // Defaults to false
    protected $logfile_path = '';
} // end Foo class
?>

Logged Events

Extending

The method #debug(mixed $message[,string $type]) is called to perform logging. Redefining this method to do something else is the easiest way to change the global logging behavior.

<?php
class My_ActiveTable extends ActiveTable
{
    protected $debug = true;
 
    // This is an example - I do NOT recommend you do this - even one pageload would
    // send you dozens of emails!
    protected function debug($message,$type='info')
    {
        send_email('admin@yourdomain.com',"[$type] ActiveTable Debug Event!",$message);
    } // end debug
} // end My_ActiveTable
 
class Foo extends My_ActiveTable
{
    protected $table_name = 'foo';
    protected $primary_key = 'foo_id'; 
} // end Foo class
?>