2009-08-19 23:55:03 +02:00
|
|
|
<?php
|
2010-04-23 02:11:41 +02:00
|
|
|
require_once 'Zend/Log/Writer/Abstract.php';
|
|
|
|
|
2009-08-19 23:55:03 +02:00
|
|
|
/**
|
2010-10-19 03:21:32 +02:00
|
|
|
* Writes an error message to a file.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2009-08-19 23:55:03 +02:00
|
|
|
* Note: You need to make sure your web server is able
|
|
|
|
* to write to the file path that you specify to write
|
|
|
|
* logs to.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2009-08-19 23:55:03 +02:00
|
|
|
* @uses error_log() built-in PHP function.
|
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
|
|
|
* @see SS_Log for more information on using writers.
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2009-08-19 23:55:03 +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_LogFileWriter extends Zend_Log_Writer_Abstract {
|
2009-08-19 23:55:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The path to the file that errors will be stored in.
|
|
|
|
* For example, "/var/logs/silverstripe/errors.log".
|
2014-08-15 08:53:05 +02:00
|
|
|
*
|
2009-08-19 23:55:03 +02:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $path;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-08-19 23:55:03 +02:00
|
|
|
/**
|
|
|
|
* Message type to pass to error_log()
|
|
|
|
* @see http://us3.php.net/manual/en/function.error-log.php
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $messageType;
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2009-08-19 23:55:03 +02:00
|
|
|
/**
|
|
|
|
* Extra headers to pass to error_log()
|
|
|
|
* @see http://us3.php.net/manual/en/function.error-log.php
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $extraHeaders;
|
|
|
|
|
|
|
|
public function __construct($path, $messageType = 3, $extraHeaders = '') {
|
|
|
|
$this->path = $path;
|
|
|
|
$this->messageType = $messageType;
|
|
|
|
$this->extraHeaders = $extraHeaders;
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public static function factory($path, $messageType = 3, $extraHeaders = '') {
|
2011-05-30 11:30:32 +02:00
|
|
|
return new SS_LogFileWriter($path, $messageType, $extraHeaders);
|
|
|
|
}
|
2009-08-19 23:55:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Write the log message to the file path set
|
|
|
|
* in this writer.
|
|
|
|
*/
|
|
|
|
public function _write($event) {
|
|
|
|
if(!$this->_formatter) {
|
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
|
|
|
$formatter = new SS_LogErrorFileFormatter();
|
2009-08-19 23:55:03 +02:00
|
|
|
$this->setFormatter($formatter);
|
|
|
|
}
|
|
|
|
$message = $this->_formatter->format($event);
|
2012-07-17 04:18:35 +02:00
|
|
|
if(!file_exists(dirname($this->path))) mkdir(dirname($this->path), 0755, true);
|
2009-08-19 23:55:03 +02:00
|
|
|
error_log($message, $this->messageType, $this->path, $this->extraHeaders);
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|