Skip to content

Commit

Permalink
FEATURE #5694 New log writer SS_SysLogWriter for logging SilverStripe…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Sean Harvey committed Oct 4, 2010
1 parent 52d421e commit 5658cd6
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions dev/SysLogWriter.php
Original file line number Diff line number Diff line change
@@ -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));
}

}

0 comments on commit 5658cd6

Please sign in to comment.