/**
* Horde Log package
*
- * @category Horde
- * @package Horde_Log
+ * @category Horde
+ * @package Horde_Log
* @subpackage Handlers
- * @author Mike Naberezny <mike@maintainable.com>
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @license http://opensource.org/licenses/bsd-license.php BSD
+ * @author Mike Naberezny <mike@maintainable.com>
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @license http://opensource.org/licenses/bsd-license.php BSD
*/
/**
- * @category Horde
- * @package Horde_Log
+ * @category Horde
+ * @package Horde_Log
* @subpackage Handlers
- * @author Mike Naberezny <mike@maintainable.com>
- * @author Chuck Hagenbuch <chuck@horde.org>
- * @license http://opensource.org/licenses/bsd-license.php BSD
+ * @author Mike Naberezny <mike@maintainable.com>
+ * @author Chuck Hagenbuch <chuck@horde.org>
+ * @license http://opensource.org/licenses/bsd-license.php BSD
*/
class Horde_Log_Handler_Syslog extends Horde_Log_Handler_Base
{
/**
- * Whether openlog has been called
- * @var bool
- */
- protected $_opened = false;
-
- /**
* Options to be set by setOption(). Sets openlog and syslog options.
* @var array
*/
);
/**
+ * Last ident set by a syslog-handler instance
+ * @var string
+ */
+ protected static $_lastIdent;
+
+ /**
+ * Last facility name set by a syslog-handler instance
+ * @var string
+ */
+ protected static $_lastFacility;
+
+ /**
* Map of log levels to syslog priorities
* @var array
*/
Horde_Log::DEBUG => LOG_DEBUG,
);
-
/**
* Write a message to the log.
*
*/
public function write($event)
{
- if (! $this->_opened) {
- if (! openlog($this->_options['ident'], $this->_options['openlogOptions'], $this->_options['facility'])) {
- throw new Horde_Log_Exception('Unable to open syslog');
- }
+ if ($this->_options['ident'] !== self::$_lastIdent ||
+ $this->_options['facility'] !== self::$_lastFacility) {
+ $this->_initializeSyslog();
}
$priority = $this->_toSyslog($event['level']);
return $this->_options['defaultPriority'];
}
+ /**
+ * Initialize syslog / set ident and facility
+ *
+ * @param string $ident ident
+ * @param string $facility syslog facility
+ * @return void
+ */
+ protected function _initializeSyslog()
+ {
+ self::$_lastIdent = $this->_options['ident'];
+ self::$_lastFacility = $this->_options['facility'];
+ if (! openlog($this->_options['ident'], $this->_options['openlogOptions'], $this->_options['facility'])) {
+ throw new Horde_Log_Exception('Unable to open syslog');
+ }
+ }
+
}