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 basic 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 'Log.php';
  11.  
  12. $logger = &Log::singleton('firephp', '', 'ident');
  13. $logger->registerErrorHandler();
  14. $logger->registerExceptionHandler();
  15. $logger->registerAssertionHandler();
  16. //$logger->setMask(PEAR_LOG_NONE);
  17.  
  18. // 1. A FirePHP LOG implicit message without label
  19. $logger->log(array('message' => "Hello World"));
  20.  
  21. // 2. A FirePHP LOG implicit message with label
  22. $logger->log(array('message' => "Log message", 'label' => "Log message label"));
  23.  
  24. // 3. A FirePHP INFO explicit message with label
  25. $logger->log(array('message' => "Info message",
  26.                    'label' => "Info message label",
  27.                    'type'=> PEAR_LOG_FIREPHP_INFO),
  28.              PEAR_LOG_INFO);
  29.  
  30. // 4. A FirePHP WARNING explicit message with label
  31. $logger->log(array('message' => "Warning message",
  32.                    'label' => "Warning message label",
  33.                    'type'=> PEAR_LOG_FIREPHP_WARN),
  34.              PEAR_LOG_WARNING);
  35.  
  36. // 5. A FirePHP ERROR explicit message with label
  37. $logger->log(array('message' => "Error message",
  38.                    'label' => "Error message label",
  39.                    'type'=> PEAR_LOG_FIREPHP_ERROR),
  40.              PEAR_LOG_ERR);
  41.  
  42. // 6. A FirePHP DUMP explicit message with label
  43. $logger->log(array('message' => apache_request_headers(),
  44.                    'label' => "RequestHeaders",
  45.                    'type'=> PEAR_LOG_FIREPHP_DUMP),
  46.              PEAR_LOG_DEBUG);
  47.  
  48. // 7. A FirePHP TRACE explicit message with label
  49. $logger->log(array('label' => "Backtrace to here",
  50.                    'type'=> PEAR_LOG_FIREPHP_TRACE),
  51.              PEAR_LOG_DEBUG);
  52.  
  53. // 8. A FirePHP TABLE explicit message with label
  54. $table   = array();
  55. $table[] = array('SQL Statement', 'Time', 'Result');
  56. $table[] = array('SELECT * FROM Foo', '0.02', array('row1','row2'));
  57. $table[] = array('SELECT * FROM Bar', '0.04', array('row1','row2'));
  58. $logger->log(array('message' => $table,
  59.                    'label' => '2 SQL queries took 0.06 seconds',
  60.                    'type' => PEAR_LOG_FIREPHP_TABLE),
  61.              PEAR_LOG_DEBUG);
  62.  
  63. // 9. A FirePHP GROUP messages using convenience functions
  64. $logger->log(array('label' => 'Convenience functions call Group',
  65.                    'type' => PEAR_LOG_FIREPHP_GROUP_START));
  66. // see also 3.
  67. $logger->info(array('message' => "Info convenience message",
  68.                    'label' => "Info convenience message label"));
  69. // see also 4.
  70. $logger->warning(array('message' => "Warning convenience message",
  71.                        'label' => "Warning convenience message label"));
  72. // see also 5.
  73. $logger->err(array('message' => "Error convenience message",
  74.                    'label' => "Error convenience message label"));
  75. // see also 6.
  76. $logger->dump(array('message' => apache_request_headers(),
  77.                     'label' => "RequestHeaders"));
  78. // see also 7.
  79. $logger->trace(array('label' => "Convenience Backtrace to here"));
  80. // see also 8.
  81. $logger->table(array('message' => $table,
  82.                      'label' => '2 SQL queries took 0.06 seconds'),
  83.                PEAR_LOG_INFO);
  84. // end of FirePHP GROUP messages
  85. $logger->log(array('type' => PEAR_LOG_FIREPHP_GROUP_END));
  86.  
  87. // 10. A FirePHP LOG explici message to display variable content
  88. $var = array('i' => 10, 'j' => 20);
  89. $logger->log(array('message' => $var, 'label' => 'Iterators'));
  90.  
  91. // 11. catch a PHP notice error (see registerErrorHandler() function)
  92. print $var['foo'] . PHP_EOL;  // raise a PHP notice , catched by driver error handler
  93.  
  94. // 12. catch a user error (see registerErrorHandler() function)
  95. trigger_error('This is an error log message.', E_USER_ERROR);
  96.  
  97. // 13. catch an assertion (see registerAssertionHandler() function)
  98. assert('mysql_query("")'); // Make an assertion that should fail
  99.  
  100. // 14. conclude with specific PHP5 exception test cases
  101. if (version_compare(phpversion(), '5.0.0', '>=')) {
  102.  
  103.     function test($arg)
  104.     {
  105.         throw new Exception('Test Exception');
  106.     }
  107.  
  108.     try {
  109.       test(array('Hello'=>'World'));
  110.     } catch(Exception $e) {
  111.       /* Log exception including stack trace & variables */
  112.       $logger->log($e, PEAR_LOG_ALERT);
  113.     }
  114.  
  115.     throw new Exception('Uncaught Exception');
  116.  
  117.     echo 'not executed';
  118. }
  119. ?>
  120. </body>
  121. </html>
generated by Generic Syntax Highlighter - GeSHi 1.0.8.1