Mika Tuupola has come up with an elegant logging mechanism that has already found its way into the official PEAR::Log package.
It’s a snap to use. Simply instantiate a “Firebug” log as such:
$log = &Log::singleton('firebug', '', 'PHP', array('buffering' => true), PEAR_LOG_DEBUG);
Output will then go to your Firebug console window:
$log->log('Debug lorem ipsum.', PEAR_LOG_DEBUG);
$log->log('Info wisi enim ad minim veniam', PEAR_LOG_INFO);
$log->log('Warning est usus legentis in', PEAR_LOG_WARNING);
$log->log('Error est notare quam', PEAR_LOG_ERR);
To split output to both the default error log as well as the Firebug console, build a “composite” log:
$log = &Log::singleton('composite');
$logFile =& parent::singleton('error_log', PEAR_LOG_TYPE_SYSTEM, 'to error log', array(), PEAR_LOG_DEBUG);
$logFire =& parent::singleton('firebug', '', 'to firebug', array('buffering'=>true), PEAR_LOG_DEBUG);
$log->addChild($logFile);
$log->addChild($logFire);