Version: current

     1 <?php
     2 require_once 'Zend/Log/Formatter/Interface.php';
     3
     4 /**
     5  * Formats SS error emails with a basic layout.
     6  *
     7  * @package sapphire
     8  * @subpackage dev
     9  */
    10 class SS_LogErrorEmailFormatter implements Zend_Log_Formatter_Interface {
    11
    12     public function format($event) {
    13         switch($event['priorityName']) {
    14             case 'ERR':
    15                 $errorType = 'Error';
    16                 $colour = 'red';
    17                 break;
    18             case 'WARN':
    19                 $errorType = 'Warning';
    20                 $colour = 'orange';
    21                 break;
    22             case 'NOTICE':
    23                 $errorType = 'Notice';
    24                 $colour = 'grey';
    25                 break;
    26         }
    27
    28         if(!is_array($event['message'])) {
    29             return false;
    30         }
    31
    32         $errno = $event['message']['errno'];
    33         $errstr = $event['message']['errstr'];
    34         $errfile = $event['message']['errfile'];
    35         $errline = $event['message']['errline'];
    36         $errcontext = $event['message']['errcontext'];
    37
    38         $data = "<div style=\"border: 5px $colour solid\">\n";
    39         $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";
    40
    41         // Get a backtrace, filtering out debug method calls
    42         $data .= SS_Backtrace::backtrace(true, false, array(
    43             'SS_LogErrorEmailFormatter->format',
    44             'SS_LogEmailWriter->_write'
    45         ));
    46
    47         $data .= "</div>\n";
    48
    49         $relfile = Director::makeRelative($errfile);
    50         if($relfile[0] == '/') $relfile = substr($relfile, 1);
    51
    52         $subject = "$errorType at $relfile line {$errline} (http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI])";
    53
    54         return array(
    55             'subject' => $subject,
    56             'data' => $data
    57         );
    58     }
    59
    60 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -