PHP code
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Log FirePHP composite examples</title>
  5. <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  6. </head>
  7. <body>
  8. <h1>Log FirePHP</h1>
  9. <?php
  10. require_once 'Log.php';
  11.  
  12. $file    = &Log::singleton('file', 'out.log', 'TEST');
  13. $firephp = &Log::singleton('firephp', '', 'TEST');
  14. $firephp->registerErrorHandler();
  15.  
  16. $composite = &Log::singleton('composite');
  17. $composite->addChild($file);
  18. $composite->addChild($firephp);
  19.  
  20. $composite->log('This event will be logged to both handlers.');
  21.  
  22. $composite->log(array('message' => "Log message", 'label' => "Log message label"));
  23. $composite->log(array('message' => "Info message",
  24.                       'label' => "Info message label",
  25.                       'type'=> PEAR_LOG_FIREPHP_INFO),
  26.                 PEAR_LOG_INFO);
  27. $composite->log(array('message' => "Warning message",
  28.                       'label' => "Warning message label",
  29.                       'type'=> PEAR_LOG_FIREPHP_WARN),
  30.                 PEAR_LOG_WARNING);
  31. $composite->log(array('message' => "Error message",
  32.                       'label' => "Error message label",
  33.                       'type'=> PEAR_LOG_FIREPHP_ERROR),
  34.                 PEAR_LOG_ERR);
  35.  
  36. $composite->log(array('message' => apache_request_headers(),
  37.                       'label' => "RequestHeaders",
  38.                       'type'=> PEAR_LOG_FIREPHP_DUMP),
  39.                 PEAR_LOG_DEBUG);
  40.  
  41. $firephp->log(array('label' => "Backtrace to here",
  42.                     'type'=> PEAR_LOG_FIREPHP_TRACE),
  43.               PEAR_LOG_DEBUG);
  44.  
  45. $table   = array();
  46. $table[] = array('SQL Statement', 'Time', 'Result');
  47. $table[] = array('SELECT * FROM Foo', '0.02', array('row1','row2'));
  48. $table[] = array('SELECT * FROM Bar', '0.04', array('row1','row2'));
  49. $composite->log(array('message' => $table,
  50.                       'label' => '2 SQL queries took 0.06 seconds',
  51.                       'type' => PEAR_LOG_FIREPHP_TABLE),
  52.                 PEAR_LOG_DEBUG);
  53.  
  54. $firephp->log(array('label' => 'Convenience functions call Group',
  55.                     'type' => PEAR_LOG_FIREPHP_GROUP_START));
  56.  
  57. $composite->info(array('message' => "Info convenience message",
  58.                        'label' => "Info convenience message label"));
  59.  
  60. $firephp->log(array('type' => PEAR_LOG_FIREPHP_GROUP_END));
  61.  
  62. $var = array('i' => 10, 'j' => 20);
  63. $composite->log(array('message' => $var, 'label' => 'Iterators'));
  64.  
  65. trigger_error('This is an error log message.', E_USER_ERROR);
  66.  
  67. function test($arg)
  68. {
  69.     throw new Exception('Test Exception');
  70. }
  71.  
  72. try {
  73.   test(array('Hello'=>'World'));
  74. } catch(Exception $e) {
  75.   /* Log exception including stack trace & variables */
  76.   $composite->log($e, PEAR_LOG_ALERT);
  77. }
  78. ?>
  79. </body>
  80. </html>
generated by Generic Syntax Highlighter - GeSHi 1.0.8.1