diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:39:39 +0000 |
commit | 8ca6cc32b2c789a3149861159ad258f2cb9491e3 (patch) | |
tree | 2492de6f1528dd44eaa169a5c1555026d9cb75ec /library/vendor/Zend/Log/Writer | |
parent | Initial commit. (diff) | |
download | icingaweb2-upstream.tar.xz icingaweb2-upstream.zip |
Adding upstream version 2.11.4.upstream/2.11.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/vendor/Zend/Log/Writer')
-rw-r--r-- | library/vendor/Zend/Log/Writer/Abstract.php | 138 | ||||
-rw-r--r-- | library/vendor/Zend/Log/Writer/Db.php | 144 | ||||
-rw-r--r-- | library/vendor/Zend/Log/Writer/Mail.php | 426 | ||||
-rw-r--r-- | library/vendor/Zend/Log/Writer/Mock.php | 80 | ||||
-rw-r--r-- | library/vendor/Zend/Log/Writer/Null.php | 55 | ||||
-rw-r--r-- | library/vendor/Zend/Log/Writer/Stream.php | 132 | ||||
-rw-r--r-- | library/vendor/Zend/Log/Writer/Syslog.php | 263 | ||||
-rw-r--r-- | library/vendor/Zend/Log/Writer/ZendMonitor.php | 130 |
8 files changed, 1368 insertions, 0 deletions
diff --git a/library/vendor/Zend/Log/Writer/Abstract.php b/library/vendor/Zend/Log/Writer/Abstract.php new file mode 100644 index 0000000..c39be13 --- /dev/null +++ b/library/vendor/Zend/Log/Writer/Abstract.php @@ -0,0 +1,138 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** Zend_Log_Filter_Priority */ + +/** + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +abstract class Zend_Log_Writer_Abstract implements Zend_Log_FactoryInterface +{ + /** + * @var array of Zend_Log_Filter_Interface + */ + protected $_filters = array(); + + /** + * Formats the log message before writing. + * + * @var Zend_Log_Formatter_Interface + */ + protected $_formatter; + + /** + * Add a filter specific to this writer. + * + * @param Zend_Log_Filter_Interface|int $filter Filter class or filter + * priority + * @return Zend_Log_Writer_Abstract + * @throws Zend_Log_Exception + */ + public function addFilter($filter) + { + if (is_int($filter)) { + $filter = new Zend_Log_Filter_Priority($filter); + } + + if (!$filter instanceof Zend_Log_Filter_Interface) { + /** @see Zend_Log_Exception */ + throw new Zend_Log_Exception('Invalid filter provided'); + } + + $this->_filters[] = $filter; + return $this; + } + + /** + * Log a message to this writer. + * + * @param array $event log data event + * @return void + */ + public function write($event) + { + /** @var Zend_Log_Filter_Interface $filter */ + foreach ($this->_filters as $filter) { + if (!$filter->accept($event)) { + return; + } + } + + // exception occurs on error + $this->_write($event); + } + + /** + * Set a new formatter for this writer + * + * @param Zend_Log_Formatter_Interface $formatter + * @return Zend_Log_Writer_Abstract + */ + public function setFormatter(Zend_Log_Formatter_Interface $formatter) + { + $this->_formatter = $formatter; + return $this; + } + + /** + * Perform shutdown activites such as closing open resources + * + * @return void + */ + public function shutdown() + {} + + /** + * Write a message to the log. + * + * @param array $event log data event + * @return void + */ + abstract protected function _write($event); + + /** + * Validate and optionally convert the config to array + * + * @param array|Zend_Config $config Zend_Config or Array + * @return array + * @throws Zend_Log_Exception + */ + static protected function _parseConfig($config) + { + if ($config instanceof Zend_Config) { + $config = $config->toArray(); + } + + if (!is_array($config)) { + throw new Zend_Log_Exception( + 'Configuration must be an array or instance of Zend_Config' + ); + } + + return $config; + } +} diff --git a/library/vendor/Zend/Log/Writer/Db.php b/library/vendor/Zend/Log/Writer/Db.php new file mode 100644 index 0000000..1c61c12 --- /dev/null +++ b/library/vendor/Zend/Log/Writer/Db.php @@ -0,0 +1,144 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** Zend_Log_Writer_Abstract */ + +/** + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Log_Writer_Db extends Zend_Log_Writer_Abstract +{ + /** + * Database adapter instance + * + * @var Zend_Db_Adapter + */ + protected $_db; + + /** + * Name of the log table in the database + * + * @var string + */ + protected $_table; + + /** + * Relates database columns names to log data field keys. + * + * @var null|array + */ + protected $_columnMap; + + /** + * Class constructor + * + * @param Zend_Db_Adapter $db Database adapter instance + * @param string $table Log table in database + * @param array $columnMap + * @return void + */ + public function __construct($db, $table, $columnMap = null) + { + $this->_db = $db; + $this->_table = $table; + $this->_columnMap = $columnMap; + } + + /** + * Create a new instance of Zend_Log_Writer_Db + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Db + */ + static public function factory($config) + { + $config = self::_parseConfig($config); + $config = array_merge(array( + 'db' => null, + 'table' => null, + 'columnMap' => null, + ), $config); + + if (isset($config['columnmap'])) { + $config['columnMap'] = $config['columnmap']; + } + + return new self( + $config['db'], + $config['table'], + $config['columnMap'] + ); + } + + /** + * Formatting is not possible on this writer + * + * @return void + * @throws Zend_Log_Exception + */ + public function setFormatter(Zend_Log_Formatter_Interface $formatter) + { + throw new Zend_Log_Exception(get_class($this) . ' does not support formatting'); + } + + /** + * Remove reference to database adapter + * + * @return void + */ + public function shutdown() + { + $this->_db = null; + } + + /** + * Write a message to the log. + * + * @param array $event event data + * @return void + * @throws Zend_Log_Exception + */ + protected function _write($event) + { + if ($this->_db === null) { + throw new Zend_Log_Exception('Database adapter is null'); + } + + if ($this->_columnMap === null) { + $dataToInsert = $event; + } else { + $dataToInsert = array(); + foreach ($this->_columnMap as $columnName => $fieldKey) { + if (isset($event[$fieldKey])) { + $dataToInsert[$columnName] = $event[$fieldKey]; + } + } + } + + $this->_db->insert($this->_table, $dataToInsert); + } +} diff --git a/library/vendor/Zend/Log/Writer/Mail.php b/library/vendor/Zend/Log/Writer/Mail.php new file mode 100644 index 0000000..571d893 --- /dev/null +++ b/library/vendor/Zend/Log/Writer/Mail.php @@ -0,0 +1,426 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** Zend_Log_Writer_Abstract */ + +/** Zend_Log_Exception */ + +/** Zend_Log_Formatter_Simple*/ + +/** + * Class used for writing log messages to email via Zend_Mail. + * + * Allows for emailing log messages at and above a certain level via a + * Zend_Mail object. Note that this class only sends the email upon + * completion, so any log entries accumulated are sent in a single email. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Log_Writer_Mail extends Zend_Log_Writer_Abstract +{ + /** + * Array of formatted events to include in message body. + * + * @var array + */ + protected $_eventsToMail = array(); + + /** + * Array of formatted lines for use in an HTML email body; these events + * are formatted with an optional formatter if the caller is using + * Zend_Layout. + * + * @var array + */ + protected $_layoutEventsToMail = array(); + + /** + * Zend_Mail instance to use + * + * @var Zend_Mail + */ + protected $_mail; + + /** + * Zend_Layout instance to use; optional. + * + * @var Zend_Layout + */ + protected $_layout; + + /** + * Optional formatter for use when rendering with Zend_Layout. + * + * @var Zend_Log_Formatter_Interface + */ + protected $_layoutFormatter; + + /** + * Array keeping track of the number of entries per priority level. + * + * @var array + */ + protected $_numEntriesPerPriority = array(); + + /** + * Subject prepend text. + * + * Can only be used of the Zend_Mail object has not already had its + * subject line set. Using this will cause the subject to have the entry + * counts per-priority level appended to it. + * + * @var string|null + */ + protected $_subjectPrependText; + + /** + * MethodMap for Zend_Mail's headers + * + * @var array + */ + protected static $_methodMapHeaders = array( + 'from' => 'setFrom', + 'to' => 'addTo', + 'cc' => 'addCc', + 'bcc' => 'addBcc', + ); + + /** + * Class constructor. + * + * Constructs the mail writer; requires a Zend_Mail instance, and takes an + * optional Zend_Layout instance. If Zend_Layout is being used, + * $this->_layout->events will be set for use in the layout template. + * + * @param Zend_Mail $mail Mail instance + * @param Zend_Layout $layout Layout instance; optional + * @return void + */ + public function __construct(Zend_Mail $mail, Zend_Layout $layout = null) + { + $this->_mail = $mail; + if (null !== $layout) { + $this->setLayout($layout); + } + $this->_formatter = new Zend_Log_Formatter_Simple(); + } + + /** + * Create a new instance of Zend_Log_Writer_Mail + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Mail + */ + static public function factory($config) + { + $config = self::_parseConfig($config); + $mail = self::_constructMailFromConfig($config); + $writer = new self($mail); + + if (isset($config['layout']) || isset($config['layoutOptions'])) { + $writer->setLayout($config); + } + if (isset($config['layoutFormatter'])) { + $layoutFormatter = new $config['layoutFormatter']; + $writer->setLayoutFormatter($layoutFormatter); + } + if (isset($config['subjectPrependText'])) { + $writer->setSubjectPrependText($config['subjectPrependText']); + } + + return $writer; + } + + /** + * Set the layout + * + * @param Zend_Layout|array $layout + * @return Zend_Log_Writer_Mail + * @throws Zend_Log_Exception + */ + public function setLayout($layout) + { + if (is_array($layout)) { + $layout = $this->_constructLayoutFromConfig($layout); + } + + if (!$layout instanceof Zend_Layout) { + throw new Zend_Log_Exception('Mail must be an instance of Zend_Layout or an array'); + } + $this->_layout = $layout; + + return $this; + } + + /** + * Construct a Zend_Mail instance based on a configuration array + * + * @param array $config + * @return Zend_Mail + * @throws Zend_Log_Exception + */ + protected static function _constructMailFromConfig(array $config) + { + $mailClass = 'Zend_Mail'; + if (isset($config['mail'])) { + $mailClass = $config['mail']; + } + + if (!array_key_exists('charset', $config)) { + $config['charset'] = null; + } + $mail = new $mailClass($config['charset']); + if (!$mail instanceof Zend_Mail) { + throw new Zend_Log_Exception($mail . 'must extend Zend_Mail'); + } + + if (isset($config['subject'])) { + $mail->setSubject($config['subject']); + } + + $headerAddresses = array_intersect_key($config, self::$_methodMapHeaders); + if (count($headerAddresses)) { + foreach ($headerAddresses as $header => $address) { + $method = self::$_methodMapHeaders[$header]; + if (is_array($address) && isset($address['name']) + && !is_numeric($address['name']) + ) { + $params = array( + $address['email'], + $address['name'] + ); + } else if (is_array($address) && isset($address['email'])) { + $params = array($address['email']); + } else { + $params = array($address); + } + call_user_func_array(array($mail, $method), $params); + } + } + + return $mail; + } + + /** + * Construct a Zend_Layout instance based on a configuration array + * + * @param array $config + * @return Zend_Layout + * @throws Zend_Log_Exception + */ + protected function _constructLayoutFromConfig(array $config) + { + $config = array_merge(array( + 'layout' => 'Zend_Layout', + 'layoutOptions' => null + ), $config); + + $layoutClass = $config['layout']; + $layout = new $layoutClass($config['layoutOptions']); + if (!$layout instanceof Zend_Layout) { + throw new Zend_Log_Exception($layout . 'must extend Zend_Layout'); + } + + return $layout; + } + + /** + * Places event line into array of lines to be used as message body. + * + * Handles the formatting of both plaintext entries, as well as those + * rendered with Zend_Layout. + * + * @param array $event Event data + * @return void + */ + protected function _write($event) + { + // Track the number of entries per priority level. + if (!isset($this->_numEntriesPerPriority[$event['priorityName']])) { + $this->_numEntriesPerPriority[$event['priorityName']] = 1; + } else { + $this->_numEntriesPerPriority[$event['priorityName']]++; + } + + $formattedEvent = $this->_formatter->format($event); + + // All plaintext events are to use the standard formatter. + $this->_eventsToMail[] = $formattedEvent; + + // If we have a Zend_Layout instance, use a specific formatter for the + // layout if one exists. Otherwise, just use the event with its + // default format. + if ($this->_layout) { + if ($this->_layoutFormatter) { + $this->_layoutEventsToMail[] = + $this->_layoutFormatter->format($event); + } else { + $this->_layoutEventsToMail[] = $formattedEvent; + } + } + } + + /** + * Gets instance of Zend_Log_Formatter_Instance used for formatting a + * message using Zend_Layout, if applicable. + * + * @return Zend_Log_Formatter_Interface|null The formatter, or null. + */ + public function getLayoutFormatter() + { + return $this->_layoutFormatter; + } + + /** + * Sets a specific formatter for use with Zend_Layout events. + * + * Allows use of a second formatter on lines that will be rendered with + * Zend_Layout. In the event that Zend_Layout is not being used, this + * formatter cannot be set, so an exception will be thrown. + * + * @param Zend_Log_Formatter_Interface $formatter + * @return Zend_Log_Writer_Mail + * @throws Zend_Log_Exception + */ + public function setLayoutFormatter(Zend_Log_Formatter_Interface $formatter) + { + if (!$this->_layout) { + throw new Zend_Log_Exception( + 'cannot set formatter for layout; ' . + 'a Zend_Layout instance is not in use'); + } + + $this->_layoutFormatter = $formatter; + return $this; + } + + /** + * Allows caller to have the mail subject dynamically set to contain the + * entry counts per-priority level. + * + * Sets the text for use in the subject, with entry counts per-priority + * level appended to the end. Since a Zend_Mail subject can only be set + * once, this method cannot be used if the Zend_Mail object already has a + * subject set. + * + * @param string $subject Subject prepend text. + * @return Zend_Log_Writer_Mail + * @throws Zend_Log_Exception + */ + public function setSubjectPrependText($subject) + { + if ($this->_mail->getSubject()) { + throw new Zend_Log_Exception( + 'subject already set on mail; ' . + 'cannot set subject prepend text'); + } + + $this->_subjectPrependText = (string) $subject; + return $this; + } + + /** + * Sends mail to recipient(s) if log entries are present. Note that both + * plaintext and HTML portions of email are handled here. + * + * @return void + */ + public function shutdown() + { + // If there are events to mail, use them as message body. Otherwise, + // there is no mail to be sent. + if (empty($this->_eventsToMail)) { + return; + } + + if ($this->_subjectPrependText !== null) { + // Tack on the summary of entries per-priority to the subject + // line and set it on the Zend_Mail object. + $numEntries = $this->_getFormattedNumEntriesPerPriority(); + $this->_mail->setSubject( + "{$this->_subjectPrependText} ({$numEntries})"); + } + + + // Always provide events to mail as plaintext. + $this->_mail->setBodyText(implode('', $this->_eventsToMail)); + + // If a Zend_Layout instance is being used, set its "events" + // value to the lines formatted for use with the layout. + if ($this->_layout) { + // Set the required "messages" value for the layout. Here we + // are assuming that the layout is for use with HTML. + $this->_layout->events = + implode('', $this->_layoutEventsToMail); + + // If an exception occurs during rendering, convert it to a notice + // so we can avoid an exception thrown without a stack frame. + try { + $this->_mail->setBodyHtml($this->_layout->render()); + } catch (Exception $e) { + trigger_error( + "exception occurred when rendering layout; " . + "unable to set html body for message; " . + "message = {$e->getMessage()}; " . + "code = {$e->getCode()}; " . + "exception class = " . get_class($e), + E_USER_NOTICE); + } + } + + // Finally, send the mail. If an exception occurs, convert it into a + // warning-level message so we can avoid an exception thrown without a + // stack frame. + try { + $this->_mail->send(); + } catch (Exception $e) { + trigger_error( + "unable to send log entries via email; " . + "message = {$e->getMessage()}; " . + "code = {$e->getCode()}; " . + "exception class = " . get_class($e), + E_USER_WARNING); + } + } + + /** + * Gets a string of number of entries per-priority level that occurred, or + * an emptry string if none occurred. + * + * @return string + */ + protected function _getFormattedNumEntriesPerPriority() + { + $strings = array(); + + foreach ($this->_numEntriesPerPriority as $priority => $numEntries) { + $strings[] = "{$priority}={$numEntries}"; + } + + return implode(', ', $strings); + } +} diff --git a/library/vendor/Zend/Log/Writer/Mock.php b/library/vendor/Zend/Log/Writer/Mock.php new file mode 100644 index 0000000..8551123 --- /dev/null +++ b/library/vendor/Zend/Log/Writer/Mock.php @@ -0,0 +1,80 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** Zend_Log_Writer_Abstract */ + +/** + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Log_Writer_Mock extends Zend_Log_Writer_Abstract +{ + /** + * array of log events + * + * @var array + */ + public $events = array(); + + /** + * shutdown called? + * + * @var boolean + */ + public $shutdown = false; + + /** + * Write a message to the log. + * + * @param array $event event data + * @return void + */ + public function _write($event) + { + $this->events[] = $event; + } + + /** + * Record shutdown + * + * @return void + */ + public function shutdown() + { + $this->shutdown = true; + } + + /** + * Create a new instance of Zend_Log_Writer_Mock + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Mock + */ + static public function factory($config) + { + return new self(); + } +} diff --git a/library/vendor/Zend/Log/Writer/Null.php b/library/vendor/Zend/Log/Writer/Null.php new file mode 100644 index 0000000..2dc3103 --- /dev/null +++ b/library/vendor/Zend/Log/Writer/Null.php @@ -0,0 +1,55 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** Zend_Log_Writer_Abstract */ + +/** + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Log_Writer_Null extends Zend_Log_Writer_Abstract +{ + /** + * Write a message to the log. + * + * @param array $event event data + * @return void + */ + protected function _write($event) + { + } + + /** + * Create a new instance of Zend_Log_Writer_Null + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Null + */ + static public function factory($config) + { + return new self(); + } +} diff --git a/library/vendor/Zend/Log/Writer/Stream.php b/library/vendor/Zend/Log/Writer/Stream.php new file mode 100644 index 0000000..95771e8 --- /dev/null +++ b/library/vendor/Zend/Log/Writer/Stream.php @@ -0,0 +1,132 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** Zend_Log_Writer_Abstract */ + +/** Zend_Log_Formatter_Simple */ + +/** + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Log_Writer_Stream extends Zend_Log_Writer_Abstract +{ + /** + * Holds the PHP stream to log to. + * + * @var null|stream + */ + protected $_stream = null; + + /** + * Class Constructor + * + * @param array|string|resource $streamOrUrl Stream or URL to open as a stream + * @param string|null $mode Mode, only applicable if a URL is given + * @return void + * @throws Zend_Log_Exception + */ + public function __construct($streamOrUrl, $mode = null) + { + // Setting the default + if (null === $mode) { + $mode = 'a'; + } + + if (is_resource($streamOrUrl)) { + if (get_resource_type($streamOrUrl) != 'stream') { + throw new Zend_Log_Exception('Resource is not a stream'); + } + + if ($mode != 'a') { + throw new Zend_Log_Exception('Mode cannot be changed on existing streams'); + } + + $this->_stream = $streamOrUrl; + } else { + if (is_array($streamOrUrl) && isset($streamOrUrl['stream'])) { + $streamOrUrl = $streamOrUrl['stream']; + } + + if (! $this->_stream = @fopen($streamOrUrl, $mode, false)) { + $msg = "\"$streamOrUrl\" cannot be opened with mode \"$mode\""; + throw new Zend_Log_Exception($msg); + } + } + + $this->_formatter = new Zend_Log_Formatter_Simple(); + } + + /** + * Create a new instance of Zend_Log_Writer_Stream + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Stream + */ + static public function factory($config) + { + $config = self::_parseConfig($config); + $config = array_merge(array( + 'stream' => null, + 'mode' => null, + ), $config); + + $streamOrUrl = isset($config['url']) ? $config['url'] : $config['stream']; + + return new self( + $streamOrUrl, + $config['mode'] + ); + } + + /** + * Close the stream resource. + * + * @return void + */ + public function shutdown() + { + if (is_resource($this->_stream)) { + fclose($this->_stream); + } + } + + /** + * Write a message to the log. + * + * @param array $event event data + * @return void + * @throws Zend_Log_Exception + */ + protected function _write($event) + { + $line = $this->_formatter->format($event); + + if (false === @fwrite($this->_stream, $line)) { + throw new Zend_Log_Exception("Unable to write to stream"); + } + } +} diff --git a/library/vendor/Zend/Log/Writer/Syslog.php b/library/vendor/Zend/Log/Writer/Syslog.php new file mode 100644 index 0000000..7a569d7 --- /dev/null +++ b/library/vendor/Zend/Log/Writer/Syslog.php @@ -0,0 +1,263 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** Zend_Log */ + +/** Zend_Log_Writer_Abstract */ + +/** + * Writes log messages to syslog + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + */ +class Zend_Log_Writer_Syslog extends Zend_Log_Writer_Abstract +{ + /** + * Maps Zend_Log priorities to PHP's syslog priorities + * + * @var array + */ + protected $_priorities = array( + Zend_Log::EMERG => LOG_EMERG, + Zend_Log::ALERT => LOG_ALERT, + Zend_Log::CRIT => LOG_CRIT, + Zend_Log::ERR => LOG_ERR, + Zend_Log::WARN => LOG_WARNING, + Zend_Log::NOTICE => LOG_NOTICE, + Zend_Log::INFO => LOG_INFO, + Zend_Log::DEBUG => LOG_DEBUG, + ); + + /** + * The default log priority - for unmapped custom priorities + * + * @var string + */ + protected $_defaultPriority = LOG_NOTICE; + + /** + * Last application name set by a syslog-writer instance + * + * @var string + */ + protected static $_lastApplication; + + /** + * Last facility name set by a syslog-writer instance + * + * @var string + */ + protected static $_lastFacility; + + /** + * Application name used by this syslog-writer instance + * + * @var string + */ + protected $_application = 'Zend_Log'; + + /** + * Facility used by this syslog-writer instance + * + * @var int + */ + protected $_facility = LOG_USER; + + /** + * Types of program available to logging of message + * + * @var array + */ + protected $_validFacilities = array(); + + /** + * Class constructor + * + * @param array $params Array of options; may include "application" and "facility" keys + * @return void + */ + public function __construct(array $params = array()) + { + if (isset($params['application'])) { + $this->_application = $params['application']; + } + + $runInitializeSyslog = true; + if (isset($params['facility'])) { + $this->setFacility($params['facility']); + $runInitializeSyslog = false; + } + + if ($runInitializeSyslog) { + $this->_initializeSyslog(); + } + } + + /** + * Create a new instance of Zend_Log_Writer_Syslog + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_Syslog + */ + static public function factory($config) + { + return new self(self::_parseConfig($config)); + } + + /** + * Initialize values facilities + * + * @return void + */ + protected function _initializeValidFacilities() + { + $constants = array( + 'LOG_AUTH', + 'LOG_AUTHPRIV', + 'LOG_CRON', + 'LOG_DAEMON', + 'LOG_KERN', + 'LOG_LOCAL0', + 'LOG_LOCAL1', + 'LOG_LOCAL2', + 'LOG_LOCAL3', + 'LOG_LOCAL4', + 'LOG_LOCAL5', + 'LOG_LOCAL6', + 'LOG_LOCAL7', + 'LOG_LPR', + 'LOG_MAIL', + 'LOG_NEWS', + 'LOG_SYSLOG', + 'LOG_USER', + 'LOG_UUCP' + ); + + foreach ($constants as $constant) { + if (defined($constant)) { + $this->_validFacilities[] = constant($constant); + } + } + } + + /** + * Initialize syslog / set application name and facility + * + * @return void + */ + protected function _initializeSyslog() + { + self::$_lastApplication = $this->_application; + self::$_lastFacility = $this->_facility; + openlog($this->_application, LOG_PID, $this->_facility); + } + + /** + * Set syslog facility + * + * @param int $facility Syslog facility + * @return Zend_Log_Writer_Syslog + * @throws Zend_Log_Exception for invalid log facility + */ + public function setFacility($facility) + { + if ($this->_facility === $facility) { + return $this; + } + + if (!count($this->_validFacilities)) { + $this->_initializeValidFacilities(); + } + + if (!in_array($facility, $this->_validFacilities)) { + throw new Zend_Log_Exception('Invalid log facility provided; please see http://php.net/openlog for a list of valid facility values'); + } + + if ('WIN' == strtoupper(substr(PHP_OS, 0, 3)) + && ($facility !== LOG_USER) + ) { + throw new Zend_Log_Exception('Only LOG_USER is a valid log facility on Windows'); + } + + $this->_facility = $facility; + $this->_initializeSyslog(); + return $this; + } + + /** + * Set application name + * + * @param string $application Application name + * @return Zend_Log_Writer_Syslog + */ + public function setApplicationName($application) + { + if ($this->_application === $application) { + return $this; + } + $this->_application = $application; + $this->_initializeSyslog(); + return $this; + } + + /** + * Close syslog. + * + * @return void + */ + public function shutdown() + { + closelog(); + } + + /** + * Write a message to syslog. + * + * @param array $event event data + * @return void + */ + protected function _write($event) + { + if (array_key_exists($event['priority'], $this->_priorities)) { + $priority = $this->_priorities[$event['priority']]; + } else { + $priority = $this->_defaultPriority; + } + + if ($this->_application !== self::$_lastApplication + || $this->_facility !== self::$_lastFacility) + { + $this->_initializeSyslog(); + } + + $message = $event['message']; + if ($this->_formatter instanceof Zend_Log_Formatter_Interface) { + $message = $this->_formatter->format($event); + } + + syslog($priority, $message); + } +} diff --git a/library/vendor/Zend/Log/Writer/ZendMonitor.php b/library/vendor/Zend/Log/Writer/ZendMonitor.php new file mode 100644 index 0000000..b59db93 --- /dev/null +++ b/library/vendor/Zend/Log/Writer/ZendMonitor.php @@ -0,0 +1,130 @@ +<?php +/** + * Zend Framework + * + * LICENSE + * + * This source file is subject to the new BSD license that is bundled + * with this package in the file LICENSE.txt. + * It is also available through the world-wide-web at this URL: + * http://framework.zend.com/license/new-bsd + * If you did not receive a copy of the license and are unable to + * obtain it through the world-wide-web, please send an email + * to license@zend.com so we can send you a copy immediately. + * + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ + +/** Zend_Log_Writer_Abstract */ + +/** + * @category Zend + * @package Zend_Log + * @subpackage Writer + * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) + * @license http://framework.zend.com/license/new-bsd New BSD License + * @version $Id$ + */ +class Zend_Log_Writer_ZendMonitor extends Zend_Log_Writer_Abstract +{ + /** + * Is Zend Monitor enabled? + * + * @var boolean + */ + protected $_isEnabled = true; + + /** + * Is this for a Zend Server intance? + * + * @var boolean + */ + protected $_isZendServer = false; + + /** + * @return void + */ + public function __construct() + { + if (!function_exists('monitor_custom_event')) { + $this->_isEnabled = false; + } + if (function_exists('zend_monitor_custom_event')) { + $this->_isZendServer = true; + } + } + + /** + * Create a new instance of Zend_Log_Writer_ZendMonitor + * + * @param array|Zend_Config $config + * @return Zend_Log_Writer_ZendMonitor + */ + static public function factory($config) + { + return new self(); + } + + /** + * Is logging to this writer enabled? + * + * If the Zend Monitor extension is not enabled, this log writer will + * fail silently. You can query this method to determine if the log + * writer is enabled. + * + * @return boolean + */ + public function isEnabled() + { + return $this->_isEnabled; + } + + /** + * Log a message to this writer. + * + * @param array $event log data event + * @return void + */ + public function write($event) + { + if (!$this->isEnabled()) { + return; + } + + parent::write($event); + } + + /** + * Write a message to the log. + * + * @param array $event log data event + * @return void + */ + protected function _write($event) + { + $priority = $event['priority']; + $message = $event['message']; + unset($event['priority'], $event['message']); + + if (!empty($event)) { + if ($this->_isZendServer) { + // On Zend Server; third argument should be the event + zend_monitor_custom_event($priority, $message, $event); + } else { + // On Zend Platform; third argument is severity -- either + // 0 or 1 -- and fourth is optional (event) + // Severity is either 0 (normal) or 1 (severe); classifying + // notice, info, and debug as "normal", and all others as + // "severe" + monitor_custom_event($priority, $message, ($priority > 4) ? 0 : 1, $event); + } + } else { + monitor_custom_event($priority, $message); + } + } +} |