Documentation
The FirePHP handler outputs log events to the Firebug console.
It supports configurable string formats and specific FirePHPCore library options.
1. Configuration
Parameter |
Type |
Default |
Description |
lineFormat |
String |
%1$s %2$s [%3$s] %4$s |
Log line format specification. |
timeFormat |
String |
%b %d %H:%M:%S |
Time stamp format (for strftime). |
maxObjectDepth |
Integer |
10 |
Maximum depth to traverse objects. |
maxArrayDepth |
Integer |
20 |
Maximum depth to traverse arrays. |
useNativeJsonEncode |
Boolean |
true |
Set to FALSE to use JSON encoder included with FirePHPCore instead of
json_encode().
|
includeLineNumbers |
Boolean |
true |
Include File and Line information in message. |
Example
PHP code
<?php
require_once 'Log.php';
$options = array('lineFormat' => '%2$s - %1$s [%3$s] %4$s',
'timeFormat' => '%Y-%m-%d %H:%M:%S',
'includeLineNumbers' => false);
$logger = &Log::singleton('firephp', '', 'ident', $options);
if (!isset($logger)) {
die('PEAR::Log firephp driver cannot be loaded. Check your install');
}
$logger->log("Hello World");
?>
Screenshot
2. Logging PHP errors
PHP's default error handler can be overridden using the Log_firephp::registerErrorHandler() method.
Example
PHP code
<?php
require_once 'Log.php';
$logger = &Log::singleton('firephp', '', 'ident');
if (!isset($logger)) {
die('PEAR::Log firephp driver cannot be loaded. Check your install');
}
$logger->registerErrorHandler();
// raise a PHP notice , catched by driver error handler
print $var['foo'] . PHP_EOL;
// raise a user error, catched by driver error handler
trigger_error('This is an error log message.', E_USER_ERROR);
?>
Screenshot
3. Logging PHP Assertions
PHP allows user-defined assert() handlers.
It can be overridden using the Log_firephp::registerAssertionHandler() method.
Example
PHP code
<?php
require_once 'Log.php';
$logger = &Log::singleton('firephp', '', 'ident');
if (!isset($logger)) {
die('PEAR::Log firephp driver cannot be loaded. Check your install');
}
$logger->registerErrorHandler();
$logger->registerAssertionHandler();
// Make an assertion that should fail
assert('mysql_query("")');
?>
Screenshot
4. Logging PHP Exceptions
PHP 5 and later support the concept of exceptions.
A custom exception handler can be assigned using the Log_firephp::registerExceptionHandler() method.
Example
PHP code
<?php
require_once 'Log.php';
$logger = &Log::singleton('firephp', '', 'ident');
if (!isset($logger)) {
die('PEAR::Log firephp driver cannot be loaded. Check your install');
}
$logger->registerExceptionHandler();
function test($arg)
{
throw new Exception('Test Exception');
}
try {
test(array('Hello'=>'World'));
} catch(Exception $e) {
$logger->log($e, PEAR_LOG_ALERT);
}
throw new Exception('Uncaught Exception');
echo 'not executed';
?>
Screenshot