From: Chuck Hagenbuch Date: Wed, 14 Jan 2009 20:31:25 +0000 (-0500) Subject: better syslog handler (thomas (at) gelf (dot) net, Bug #7845) X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a5f611b0d8aeab5fb468b2500481a30c21803c99;p=horde.git better syslog handler (thomas (at) gelf (dot) net, Bug #7845) --- diff --git a/framework/Log/lib/Horde/Log/Handler/Syslog.php b/framework/Log/lib/Horde/Log/Handler/Syslog.php index db1fb820b..d216451d5 100644 --- a/framework/Log/lib/Horde/Log/Handler/Syslog.php +++ b/framework/Log/lib/Horde/Log/Handler/Syslog.php @@ -2,31 +2,25 @@ /** * Horde Log package * - * @category Horde - * @package Horde_Log + * @category Horde + * @package Horde_Log * @subpackage Handlers - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @license http://opensource.org/licenses/bsd-license.php BSD + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @license http://opensource.org/licenses/bsd-license.php BSD */ /** - * @category Horde - * @package Horde_Log + * @category Horde + * @package Horde_Log * @subpackage Handlers - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @license http://opensource.org/licenses/bsd-license.php BSD + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @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 */ @@ -38,6 +32,18 @@ class Horde_Log_Handler_Syslog extends Horde_Log_Handler_Base ); /** + * 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 */ @@ -52,7 +58,6 @@ class Horde_Log_Handler_Syslog extends Horde_Log_Handler_Base Horde_Log::DEBUG => LOG_DEBUG, ); - /** * Write a message to the log. * @@ -61,10 +66,9 @@ class Horde_Log_Handler_Syslog extends Horde_Log_Handler_Base */ 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']); @@ -90,4 +94,20 @@ class Horde_Log_Handler_Syslog extends Horde_Log_Handler_Base 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'); + } + } + }