<?php
@author pear@laurent-laville.org @access @category @package @version @license http://www.php.net/license/3_0.txt require_once 'ErrorStack.php';
require_once 'myPHPLogger.php';
define ('MYPACKAGE_ERROR_NOFILE', 10);
define ('MYPACKAGE_ERROR_DBCRIT', 20);
define ('MYPACKAGE_DEBUG_ERRORHANDLING', 30);
function dump($title, $e)
{
echo "<h1> $title </h1>";
echo '<pre>';
var_dump($e);
echo '</pre>';
echo '<hr/>';
}
function handleError($err)
{
if ($err['level'] == 'exception') {
$message = $err['message'];
var_dump($err['context']);
die($message);
} else {
printf('<b>%1$s:</b> %2$s ', ucfirst($err['level']), $err['message']);
echo '<br/><hr/>';
}
}
ini_set('display_errors',1);
ini_set('log_errors',1);
$includes = get_included_files();
dump('included_files', $includes);
$global_stack = &PEAR_ErrorStack::singleton('MyPackage');
$globalLog = 'handleError';
PEAR_ErrorStack::setDefaultLogger($globalLog);
$file = 'FTP.php';
$path = str_replace('\\', '/', ini_get('include_path'));
$msg = 'No file "%file%" found, check the path "%path%"';
$global_stack->push(MYPACKAGE_ERROR_NOFILE, 'warning',
array('file' => $file, 'path' => $path),
$msg);
@see $global_stack->setLogger($defLog);
$dsn = 'mysql://user:pass@localhost/db';
$query = 'select * from dual';
$msg = 'Database Error: Contact Administrator immediately';
$global_stack->push(MYPACKAGE_ERROR_DBCRIT, 'critical',
array('query' => $query, 'dsn' => $dsn),
$msg);
@see $global_stack->setLogger($customLog);
$handler = sprintf('(%s) %s', gettype($customLog), get_class($customLog));
$msg = 'Error Handler = %errorHandling%';
$global_stack->push(MYPACKAGE_DEBUG_ERRORHANDLING, 'debug',
array('errorHandling' => $handler),
$msg);
$errors = $global_stack->getErrors();
dump('MyPackage error_stack', $errors);
?> |