book 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
  1. <?php
  2. require_once 'Log.php';
  3.  
  4. $options = array('lineFormat' => '%2$s - %1$s [%3$s] %4$s',
  5.                  'timeFormat' => '%Y-%m-%d %H:%M:%S',
  6.                  'includeLineNumbers' => false);
  7.  
  8. $logger = &Log::singleton('firephp', '', 'ident', $options);
  9. if (!isset($logger)) {
  10.     die('PEAR::Log firephp driver cannot be loaded. Check your install');
  11. }
  12.  
  13. $logger->log("Hello World");
  14. ?>
generated by Generic Syntax Highlighter - GeSHi

Screenshot

configure example

2. Logging PHP errors

PHP's default error handler can be overridden using the Log_firephp::registerErrorHandler() method.

Example

PHP code
  1. <?php
  2. require_once 'Log.php';
  3.  
  4. $logger = &Log::singleton('firephp', '', 'ident');
  5. if (!isset($logger)) {
  6.     die('PEAR::Log firephp driver cannot be loaded. Check your install');
  7. }
  8. $logger->registerErrorHandler();
  9.  
  10. // raise a PHP notice , catched by driver error handler
  11. print $var['foo'] . PHP_EOL;
  12.  
  13. // raise a user error, catched by driver error handler
  14. trigger_error('This is an error log message.', E_USER_ERROR);
  15. ?>
generated by Generic Syntax Highlighter - GeSHi

Screenshot

registerErrorHandler example

3. Logging PHP Assertions

PHP allows user-defined assert() handlers. It can be overridden using the Log_firephp::registerAssertionHandler() method.

Example

PHP code
  1. <?php
  2. require_once 'Log.php';
  3.  
  4. $logger = &Log::singleton('firephp', '', 'ident');
  5. if (!isset($logger)) {
  6.     die('PEAR::Log firephp driver cannot be loaded. Check your install');
  7. }
  8. $logger->registerErrorHandler();
  9. $logger->registerAssertionHandler();
  10.  
  11. // Make an assertion that should fail
  12. assert('mysql_query("")');
  13. ?>
generated by Generic Syntax Highlighter - GeSHi

Screenshot

registerAssertionHandler example

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
  1. <?php
  2. require_once 'Log.php';
  3.  
  4. $logger = &Log::singleton('firephp', '', 'ident');
  5. if (!isset($logger)) {
  6.     die('PEAR::Log firephp driver cannot be loaded. Check your install');
  7. }
  8.  
  9. $logger->registerExceptionHandler();
  10.  
  11. function test($arg)
  12. {
  13.     throw new Exception('Test Exception');
  14. }
  15.  
  16. try {
  17.     test(array('Hello'=>'World'));
  18. } catch(Exception $e) {
  19.     $logger->log($e, PEAR_LOG_ALERT);
  20. }
  21.  
  22. throw new Exception('Uncaught Exception');
  23.  
  24. echo 'not executed';
  25. ?>
generated by Generic Syntax Highlighter - GeSHi

Screenshot

registerExceptionHandler example