silverstripe-framework/dev/SSLogErrorEmailFormatter.php
Sean Harvey a682ab9c0e API CHANGE Moved Debug::backtrace() to SSBacktrace::backtrace()
API CHANGE Moved Debug::get_rendered_backtrace() to SSBacktrace::get_rendered_backtrace()
ENHANCEMENT Added SSLog, SSLogEmailWriter and SSLogErrorEmailFormatter for silverstripe message reporting
API CHANGE Debug::send_errors_to() and Debug::send_warnings_to() are deprecated in favour of SSLog. See class documentation for SSLog on configuration of error email notifications
MINOR Added SSLogTest for basic testing of the SSLog and SSLogEmailWriter classes



git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@84774 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-08-19 03:55:23 +00:00

52 lines
1.4 KiB
PHP

<?php
/**
* Formats SS error emails with a basic layout.
* @package sapphire
* @subpackage dev
*/
require_once 'Zend/Log/Formatter/Interface.php';
class SSLogErrorEmailFormatter implements Zend_Log_Formatter_Interface {
public function format($event) {
$errorType = ($event['priorityName'] == 'WARN') ? 'Warning' : 'Error';
if($event['priorityName'] == 'WARN') {
$colour = "orange";
} else {
$colour = "red";
}
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
$data .= SSBacktrace::backtrace(true, false, array(
'SSLogErrorEmailFormatter->format',
'SSLogEmailWriter->_write'
));
$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
);
}
}