mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
FEATURE #5694 New log writer SS_SysLogWriter for logging SilverStripe errors to the system log (thanks rorschach!)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@111674 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
52d421e3ca
commit
5658cd68a2
43
dev/SysLogWriter.php
Normal file
43
dev/SysLogWriter.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
require_once 'Zend/Log/Writer/Abstract.php';
|
||||
|
||||
/**
|
||||
* Sends an error message to the system log whenever an
|
||||
* error occurs.
|
||||
*
|
||||
* @see SS_Log for more information on using writers
|
||||
* @uses Zend_Log_Writer_Abstract
|
||||
* @package sapphire
|
||||
* @subpackage dev
|
||||
*/
|
||||
class SS_SysLogWriter extends Zend_Log_Writer_Abstract {
|
||||
|
||||
/**
|
||||
* @param string $ident Identity of log, defaults to "Silverstripe_log" if null
|
||||
* @param $options Option constants, passed to openlog()
|
||||
* @param $facility Type of program logging the message, passed to openlog()
|
||||
*/
|
||||
public function __construct($ident = null, $options = null, $facility = LOG_LOCAL0) {
|
||||
if(!$ident) $ident = 'SilverStripe_log';
|
||||
if(!$options) $options = LOG_PID | LOG_PERROR;
|
||||
openlog($ident, $options, $facility);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the log when this object is destroyed.
|
||||
*/
|
||||
public function __destruct() {
|
||||
closelog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to the system log with the event details.
|
||||
* @param array $event Error details
|
||||
*/
|
||||
public function _write($event) {
|
||||
// If no formatter set up, use default then log the event
|
||||
if(!$this->_formatter) $this->setFormatter(new SS_LogErrorFileFormatter());
|
||||
syslog($event['priority'], $this->_formatter->format($event));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user