ENHANCEMENT Debug and DebugView now supports showing E_NOTICE and E_USER_NOTICE level errors, whereas before they were not handled

ENHANCEMENT Updated SSLogErrorEmailFormatter to support NOTICE priority level logging
MINOR Updated SSBacktrace to ignore Debug::noticeHandler() in the backtrace



git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84816 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2009-08-19 06:03:57 +00:00
parent 02f4ff232f
commit 1494169201
4 changed files with 43 additions and 10 deletions

View File

@ -5,12 +5,10 @@
* Attaches custom methods to the default error handling hooks * Attaches custom methods to the default error handling hooks
* in PHP. Currently, two levels of error are supported: * in PHP. Currently, two levels of error are supported:
* *
* - Notice
* - Warning * - Warning
* - Error * - Error
* *
* Notice level errors are currently unsupported, and will be passed
* directly to the normal PHP error output.
*
* Uncaught exceptions are currently passed to the debug * Uncaught exceptions are currently passed to the debug
* reporter as standard PHP errors. * reporter as standard PHP errors.
* *
@ -19,7 +17,6 @@
* class documentation. * class documentation.
* *
* @todo add support for user defined config: Debug::die_on_notice(true | false) * @todo add support for user defined config: Debug::die_on_notice(true | false)
* @todo add appropriate handling for E_NOTICE and E_USER_NOTICE levels
* @todo better way of figuring out the error context to display in highlighted source * @todo better way of figuring out the error context to display in highlighted source
* *
* @package sapphire * @package sapphire
@ -196,6 +193,26 @@ class Debug {
set_exception_handler('exceptionHandler'); set_exception_handler('exceptionHandler');
} }
static function noticeHandler($errno, $errstr, $errfile, $errline, $errcontext) {
if(error_reporting() == 0) return;
// Send out the error details to the logger for writing
SSLog::log(
array(
'errno' => $errno,
'errstr' => $errstr,
'errfile' => $errfile,
'errline' => $errline,
'errcontext' => $errcontext
),
SSLog::NOTICE
);
if(Director::isDev()) {
self::showError($errno, $errstr, $errfile, $errline, $errcontext, "Notice");
}
}
/** /**
* Handle a non-fatal warning error thrown by PHP interpreter. * Handle a non-fatal warning error thrown by PHP interpreter.
* *
@ -628,12 +645,15 @@ function errorHandler($errno, $errstr, $errfile, $errline) {
Debug::fatalHandler($errno, $errstr, $errfile, $errline, null); Debug::fatalHandler($errno, $errstr, $errfile, $errline, null);
break; break;
case E_NOTICE:
case E_WARNING: case E_WARNING:
case E_CORE_WARNING: case E_CORE_WARNING:
case E_USER_WARNING: case E_USER_WARNING:
Debug::warningHandler($errno, $errstr, $errfile, $errline, null); Debug::warningHandler($errno, $errstr, $errfile, $errline, null);
break; break;
case E_NOTICE:
case E_USER_NOTICE:
Debug::noticeHandler($errno, $errstr, $errfile, $errline, null);
break;
} }
} }

View File

@ -26,6 +26,10 @@ class DebugView {
'title' => 'Notice', 'title' => 'Notice',
'class' => 'notice' 'class' => 'notice'
), ),
E_USER_NOTICE => array(
'title' => 'Notice',
'class' => 'notice'
),
E_CORE_ERROR => array( E_CORE_ERROR => array(
'title' => 'Core Error', 'title' => 'Core Error',
'class' => 'error' 'class' => 'error'

View File

@ -37,6 +37,7 @@ class SSBacktrace {
'CliDebugView->writeTrace', 'CliDebugView->writeTrace',
'Debug::emailError', 'Debug::emailError',
'Debug::warningHandler', 'Debug::warningHandler',
'Debug::noticeHandler',
'Debug::fatalHandler', 'Debug::fatalHandler',
'errorHandler', 'errorHandler',
'Debug::showError', 'Debug::showError',

View File

@ -10,11 +10,19 @@ require_once 'Zend/Log/Formatter/Interface.php';
class SSLogErrorEmailFormatter implements Zend_Log_Formatter_Interface { class SSLogErrorEmailFormatter implements Zend_Log_Formatter_Interface {
public function format($event) { public function format($event) {
$errorType = ($event['priorityName'] == 'WARN') ? 'Warning' : 'Error'; switch($event['priorityName']) {
if($event['priorityName'] == 'WARN') { case 'ERR':
$colour = "orange"; $errorType = 'Error';
} else { $colour = 'red';
$colour = "red"; break;
case 'WARN':
$errorType = 'Warning';
$colour = 'warning';
break;
case 'NOTICE':
$errorType = 'Notice';
$colour = 'grey';
break;
} }
if(!is_array($event['message'])) { if(!is_array($event['message'])) {