00001 <?php 00024 require_once 'Zend/Log/Writer/Abstract.php'; 00025 00035 class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract 00036 { 00041 protected $_priorities = array( 00042 Zend_Log::EMERG => LOG_EMERG, 00043 Zend_Log::ALERT => LOG_ALERT, 00044 Zend_Log::CRIT => LOG_CRIT, 00045 Zend_Log::ERR => LOG_ERR, 00046 Zend_Log::WARN => LOG_WARNING, 00047 Zend_Log::NOTICE => LOG_NOTICE, 00048 Zend_Log::INFO => LOG_INFO, 00049 Zend_Log::DEBUG => LOG_DEBUG, 00050 ); 00051 00056 protected $_defaultPriority = LOG_NOTICE; 00057 00062 protected static $_lastApplication; 00063 00068 protected static $_lastFacility; 00069 00074 protected $_application = 'Zend_Log'; 00075 00080 protected $_facility = LOG_USER; 00081 00088 public function __construct(array $params = array()) 00089 { 00090 if (isset($params['application'])) { 00091 $this->_application = $params['application']; 00092 } 00093 if (isset($params['facility'])) { 00094 $this->_facility = $params['facility']; 00095 } 00096 $this->_initializeSyslog(); 00097 } 00098 00106 protected function _initializeSyslog() 00107 { 00108 self::$_lastApplication = $this->_application; 00109 self::$_lastFacility = $this->_facility; 00110 openlog($this->_application, LOG_PID, $this->_facility); 00111 } 00112 00119 public function setFacility($facility) 00120 { 00121 if ($this->_facility === $facility) { 00122 return; 00123 } 00124 $this->_facility = $facility; 00125 $this->_initializeSyslog(); 00126 } 00127 00134 public function setApplicationName($application) 00135 { 00136 if ($this->_application === $application) { 00137 return; 00138 } 00139 $this->_application = $application; 00140 $this->_initializeSyslog(); 00141 } 00142 00148 public function shutdown() 00149 { 00150 closelog(); 00151 } 00152 00159 protected function _write($event) 00160 { 00161 if (array_key_exists($event['priority'], $this->_priorities)) { 00162 $priority = $this->_priorities[$event['priority']]; 00163 } else { 00164 $priority = $this->_defaultPriority; 00165 } 00166 00167 if ($this->_application !== self::$_lastApplication 00168 || $this->_facility !== self::$_lastFacility) 00169 { 00170 $this->_initializeSyslog(); 00171 } 00172 00173 syslog($priority, $event['message']); 00174 } 00175 }