2009-08-19 05:55:23 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Formats SS error emails with a basic layout.
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage dev
|
|
|
|
*/
|
|
|
|
|
|
|
|
require_once 'Zend/Log/Formatter/Interface.php';
|
|
|
|
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
class SS_LogErrorEmailFormatter implements Zend_Log_Formatter_Interface {
|
2009-08-19 05:55:23 +02:00
|
|
|
|
|
|
|
public function format($event) {
|
2009-08-19 08:03:57 +02:00
|
|
|
switch($event['priorityName']) {
|
|
|
|
case 'ERR':
|
|
|
|
$errorType = 'Error';
|
|
|
|
$colour = 'red';
|
|
|
|
break;
|
|
|
|
case 'WARN':
|
|
|
|
$errorType = 'Warning';
|
2009-08-19 08:19:53 +02:00
|
|
|
$colour = 'orange';
|
2009-08-19 08:03:57 +02:00
|
|
|
break;
|
|
|
|
case 'NOTICE':
|
|
|
|
$errorType = 'Notice';
|
|
|
|
$colour = 'grey';
|
|
|
|
break;
|
2009-08-19 05:55:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!is_array($event['message'])) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$errno = $event['message']['errno'];
|
|
|
|
$errstr = $event['message']['errstr'];
|
|
|
|
$errfile = $event['message']['errfile'];
|
|
|
|
$errline = $event['message']['errline'];
|
|
|
|
$errcontext = $event['message']['errcontext'];
|
|
|
|
|
|
|
|
$data = "<div style=\"border: 5px $colour solid\">\n";
|
|
|
|
$data .= "<p style=\"color: white; background-color: $colour; margin: 0\">$errorType: $errstr<br /> At line $errline in $errfile\n<br />\n<br />\n</p>\n";
|
|
|
|
|
|
|
|
// Get a backtrace, filtering out debug method calls
|
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Andrew Short <andrewjshort@gmail.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@90075 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:31 +01:00
|
|
|
$data .= SS_Backtrace::backtrace(true, false, array(
|
|
|
|
'SS_LogErrorEmailFormatter->format',
|
|
|
|
'SS_LogEmailWriter->_write'
|
2009-08-19 05:55:23 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
$data .= "</div>\n";
|
|
|
|
|
|
|
|
$relfile = Director::makeRelative($errfile);
|
|
|
|
if($relfile[0] == '/') $relfile = substr($relfile, 1);
|
|
|
|
|
|
|
|
$subject = "$errorType at $relfile line {$errline} (http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI])";
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'subject' => $subject,
|
|
|
|
'data' => $data
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|