Version: current

     1 <?php
     2 require_once 'Zend/Log/Formatter/Interface.php';
     3
     4 /**
     5  * Formats SS error entries in an error file log.
     6  * Format: [d-M-Y h:i:s] <type> at <file> line <line>: <errormessage> <url>
     7  * @package sapphire
     8  * @subpackage dev
     9  */
    10 class SS_LogErrorFileFormatter implements Zend_Log_Formatter_Interface {
    11
    12     public function format($event) {
    13         $errno = $event['message']['errno'];
    14         $errstr = $event['message']['errstr'];
    15         $errfile = $event['message']['errfile'];
    16         $errline = $event['message']['errline'];
    17         $errcontext = $event['message']['errcontext'];
    18
    19         switch($event['priorityName']) {
    20             case 'ERR':
    21                 $errtype = 'Error';
    22                 break;
    23             case 'WARN':
    24                 $errtype = 'Warning';
    25                 break;
    26             case 'NOTICE':
    27                 $errtype = 'Notice';
    28                 break;
    29         }
    30
    31         $urlSuffix = '';
    32         $relfile = Director::makeRelative($errfile);
    33         if($relfile[0] == '/') $relfile = substr($relfile, 1);
    34         if(isset($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] && isset($_SERVER['REQUEST_URI'])) {
    35             $urlSuffix = " (http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI])";
    36         }
    37
    38         return '[' . date('d-M-Y h:i:s') . "] $errtype at $relfile line $errline: $errstr$urlSuffix" . PHP_EOL;
    39     }
    40
    41 }

[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. -