2009-08-19 05:55:23 +02:00
|
|
|
<?php
|
2010-04-23 02:11:41 +02:00
|
|
|
require_once 'Zend/Log/Formatter/Interface.php';
|
|
|
|
|
2009-08-19 05:55:23 +02:00
|
|
|
/**
|
|
|
|
* Formats SS error emails with a basic layout.
|
2010-04-23 02:11:41 +02:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-08-19 05:55:23 +02:00
|
|
|
* @subpackage dev
|
|
|
|
*/
|
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;
|
2014-02-24 03:38:53 +01:00
|
|
|
default:
|
|
|
|
$errorType = $event['priorityName'];
|
|
|
|
$colour = 'grey';
|
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'];
|
|
|
|
|
2012-02-06 21:55:27 +01:00
|
|
|
$data = '';
|
|
|
|
$data .= '<style type="text/css">html, body, table {font-family: sans-serif; font-size: 12px;}</style>';
|
|
|
|
$data .= "<div style=\"border: 5px $colour solid;\">\n";
|
2013-06-21 00:32:08 +02:00
|
|
|
$data .= "<p style=\"color: white; background-color: $colour; margin: 0\">[$errorType] ";
|
|
|
|
$data .= nl2br(htmlspecialchars($errstr))."<br />$errfile:$errline\n<br />\n<br />\n</p>\n";
|
2009-08-19 05:55:23 +02:00
|
|
|
|
2013-01-23 20:37:47 +01:00
|
|
|
// Render the provided backtrace
|
|
|
|
$data .= SS_Backtrace::get_rendered_backtrace($errcontext);
|
2009-08-19 05:55:23 +02:00
|
|
|
|
2012-02-06 17:52:19 +01:00
|
|
|
// Compile extra data
|
|
|
|
$blacklist = array('message', 'timestamp', 'priority', 'priorityName');
|
|
|
|
$extras = array_diff_key($event, array_combine($blacklist, $blacklist));
|
|
|
|
if($extras) {
|
|
|
|
$data .= "<h3>Details</h3>\n";
|
|
|
|
$data .= "<table class=\"extras\">\n";
|
|
|
|
foreach($extras as $k => $v) {
|
|
|
|
if(is_array($v)) $v = var_export($v, true);
|
|
|
|
$data .= sprintf(
|
|
|
|
"<tr><td><strong>%s</strong></td><td><pre>%s</pre></td></tr>\n", $k, $v);
|
|
|
|
}
|
|
|
|
$data .= "</table>\n";
|
|
|
|
}
|
|
|
|
|
2009-08-19 05:55:23 +02:00
|
|
|
$data .= "</div>\n";
|
|
|
|
|
|
|
|
$relfile = Director::makeRelative($errfile);
|
2011-08-23 14:34:59 +02:00
|
|
|
if($relfile && $relfile[0] == '/') $relfile = substr($relfile, 1);
|
2010-11-24 07:23:51 +01:00
|
|
|
|
2014-03-04 23:47:02 +01:00
|
|
|
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null;
|
|
|
|
$uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null;
|
2009-08-19 05:55:23 +02:00
|
|
|
|
2012-02-06 23:04:42 +01:00
|
|
|
$subject = "[$errorType] in $relfile:{$errline} (http://{$host}{$uri})";
|
2009-08-19 05:55:23 +02:00
|
|
|
|
|
|
|
return array(
|
|
|
|
'subject' => $subject,
|
|
|
|
'data' => $data
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|