Version: current

     1 <?php
     2 require_once 'Zend/Log/Writer/Abstract.php';
     3
     4 /**
     5  * Sends an error message to an email whenever an
     6  * error occurs in sapphire.
     7  *
     8  * Note: You need to make sure your web server is able
     9  * to write to the file path that you specify to write
    10  * logs to.
    11  *
    12  * @uses error_log() built-in PHP function.
    13  * @see SS_Log for more information on using writers.
    14  *
    15  * @package sapphire
    16  * @subpackage dev
    17  */
    18 class SS_LogFileWriter extends Zend_Log_Writer_Abstract {
    19
    20     /**
    21      * The path to the file that errors will be stored in.
    22      * For example, "/var/logs/silverstripe/errors.log".
    23      *
    24      * @var string
    25      */
    26     protected $path;
    27
    28     /**
    29      * Message type to pass to error_log()
    30      * @see http://us3.php.net/manual/en/function.error-log.php
    31      * @var int
    32      */
    33     protected $messageType;
    34
    35     /**
    36      * Extra headers to pass to error_log()
    37      * @see http://us3.php.net/manual/en/function.error-log.php
    38      * @var string
    39      */
    40     protected $extraHeaders;
    41
    42     public function __construct($path, $messageType = 3, $extraHeaders = '') {
    43         $this->path = $path;
    44         $this->messageType = $messageType;
    45         $this->extraHeaders = $extraHeaders;
    46     }
    47
    48     /**
    49      * Write the log message to the file path set
    50      * in this writer.
    51      */
    52     public function _write($event) {
    53         if(!$this->_formatter) {
    54             $formatter = new SS_LogErrorFileFormatter();
    55             $this->setFormatter($formatter);
    56         }
    57         $message = $this->_formatter->format($event);
    58         error_log($message, $this->messageType, $this->path, $this->extraHeaders);
    59     }
    60
    61 }

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