<?php
/**
* Composite usage of Growl PEAR::Log driver
*
* PHP versions 4 and 5
*
* @category Logging
* @package Log
* @author Laurent Laville <pear@laurent-laville.org>
* @copyright 2009 Laurent Laville
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @version CVS: $Id:$
* @link http://pear.php.net/package/Log
* @example examples/growl_composite.php
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Log Growl composite examples</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Log Growl</h1>
<?php
require_once 'Log.php';
$file = &Log::singleton('file', 'out.log', 'TEST');
$growl = &Log::singleton('growl', '', 'TEST');
if (isset($growl)) {
$growl->registerErrorHandler();
$growl->registerExceptionHandler();
}
$composite = &Log::singleton('composite');
$composite->addChild($file);
$composite->addChild($growl);
$composite->log('This simple event will be logged to both handlers.');
$composite->log(array('message' => "Be carefull message"), PEAR_LOG_WARNING);
$var = array('i' => 10, 'j' => 20);
$composite->log(
array(
'message' => var_export($var, true),
'priority' => GROWL_PRIORITY_MODERATE,
'sticky' => true
)
);
// catch a PHP notice error (see registerErrorHandler() function)
print $var['foo'];
// 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 catchable exception */
$composite->log($e, PEAR_LOG_ALERT);
}
throw new Exception('Uncaught Exception');
echo 'not executed';
}
?>
</body>
</html>