Permalink
Browse files

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...
halkyon committed Oct 4, 2010
1 parent 52d421e commit 5658cd68a26027d5429a28b9dabe9c7afa4d4a86
Showing with 43 additions and 0 deletions.
  1. +43 −0 dev/SysLogWriter.php
View
@@ -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.