-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Sean Harvey
committed
Oct 4, 2010
1 parent
52d421e
commit 5658cd6
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |