<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Log FirePHP basic examples</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Log FirePHP</h1>
<?php
require 'Log.php';
$logger = &Log::singleton('firephp', '', 'ident');
$logger->registerErrorHandler();
$logger->registerExceptionHandler();
$logger->registerAssertionHandler();
//$logger->setMask(PEAR_LOG_NONE);
// 1. A FirePHP LOG implicit message without label
$logger->log(array('message' => "Hello World"));
// 2. A FirePHP LOG implicit message with label
$logger->log(array('message' => "Log message", 'label' => "Log message label"));
// 3. A FirePHP INFO explicit message with label
$logger->log(array('message' => "Info message",
'label' => "Info message label",
'type'=> PEAR_LOG_FIREPHP_INFO),
PEAR_LOG_INFO);
// 4. A FirePHP WARNING explicit message with label
$logger->log(array('message' => "Warning message",
'label' => "Warning message label",
'type'=> PEAR_LOG_FIREPHP_WARN),
PEAR_LOG_WARNING);
// 5. A FirePHP ERROR explicit message with label
$logger->log(array('message' => "Error message",
'label' => "Error message label",
'type'=> PEAR_LOG_FIREPHP_ERROR),
PEAR_LOG_ERR);
// 6. A FirePHP DUMP explicit message with label
$logger->log(array('message' => apache_request_headers(),
'label' => "RequestHeaders",
'type'=> PEAR_LOG_FIREPHP_DUMP),
PEAR_LOG_DEBUG);
// 7. A FirePHP TRACE explicit message with label
$logger->log(array('label' => "Backtrace to here",
'type'=> PEAR_LOG_FIREPHP_TRACE),
PEAR_LOG_DEBUG);
// 8. A FirePHP TABLE explicit message with label
$table = array();
$table[] = array('SQL Statement', 'Time', 'Result');
$table[] = array('SELECT * FROM Foo', '0.02', array('row1','row2'));
$table[] = array('SELECT * FROM Bar', '0.04', array('row1','row2'));
$logger->log(array('message' => $table,
'label' => '2 SQL queries took 0.06 seconds',
'type' => PEAR_LOG_FIREPHP_TABLE),
PEAR_LOG_DEBUG);
// 9. A FirePHP GROUP messages using convenience functions
$logger->log(array('label' => 'Convenience functions call Group',
'type' => PEAR_LOG_FIREPHP_GROUP_START));
// see also 3.
$logger->info(array('message' => "Info convenience message",
'label' => "Info convenience message label"));
// see also 4.
$logger->warning(array('message' => "Warning convenience message",
'label' => "Warning convenience message label"));
// see also 5.
$logger->err(array('message' => "Error convenience message",
'label' => "Error convenience message label"));
// see also 6.
$logger->dump(array('message' => apache_request_headers(),
'label' => "RequestHeaders"));
// see also 7.
$logger->trace(array('label' => "Convenience Backtrace to here"));
// see also 8.
$logger->table(array('message' => $table,
'label' => '2 SQL queries took 0.06 seconds'),
PEAR_LOG_INFO);
// end of FirePHP GROUP messages
$logger->log(array('type' => PEAR_LOG_FIREPHP_GROUP_END));
// 10. A FirePHP LOG explici message to display variable content
$var = array('i' => 10, 'j' => 20);
$logger->log(array('message' => $var, 'label' => 'Iterators'));
// 11. catch a PHP notice error (see registerErrorHandler() function)
print $var['foo'] . PHP_EOL; // raise a PHP notice , catched by driver error handler
// 12. catch a user error (see registerErrorHandler() function)
trigger_error('This is an error log message.', E_USER_ERROR);
// 13. catch an assertion (see registerAssertionHandler() function)
assert('mysql_query("")'); // Make an assertion that should fail
// 14. conclude with specific PHP5 exception test cases
if (version_compare(phpversion(), '5.0.0', '>=')) {
function test($arg)
{
throw new Exception('Test Exception');
}
try {
test(array('Hello'=>'World'));
} catch(Exception $e) {
/* Log exception including stack trace & variables */
$logger->log($e, PEAR_LOG_ALERT);
}
throw new Exception('Uncaught Exception');
echo 'not executed';
}
?>
</body>
</html>