diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/doc/Horde/Log/COPYING php-horde-log-2.1.0/Horde_Log-2.0.1/doc/Horde/Log/COPYING --- php-horde-log-2.0.1/Horde_Log-2.0.1/doc/Horde/Log/COPYING 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/doc/Horde/Log/COPYING 1970-01-01 00:00:00.000000000 +0000 @@ -1,24 +0,0 @@ - Copyright 1999-2012 Horde LLC. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE HORDE PROJECT -OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Exception.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Exception.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Exception.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Exception.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - */ -class Horde_Log_Exception extends Horde_Exception_Wrapped -{ -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter/Constraint.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter/Constraint.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter/Constraint.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter/Constraint.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,143 +0,0 @@ - - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ - -/** - * Filters log events using defined constraints on one or more fields of the - * $event array. - * - * @author James Pepin - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - * - * @todo Implement constraint objects for the different types of filtering ie - * regex,required,type..etc.. so we can add different constaints ad infinitum. - */ -class Horde_Log_Filter_Constraint implements Horde_Log_Filter -{ - /** - * Constraint list. - * - * @var array - */ - protected $_constraints = array(); - - /** - * Default constraint coupler. - * - * @var Horde_Constraint_Coupler - * @default Horde_Constraint_And - */ - protected $_coupler; - - /** - * Constructor - * - * @param Horde_Constraint_Coupler $coupler The default kind of - * constraint to use to couple - * multiple constraints. - * Defaults to And. - */ - public function __construct(Horde_Constraint_Coupler $coupler = null) - { - $this->_coupler = is_null($coupler) - ? new Horde_Constraint_And() - : $coupler; - } - - /** - * Add a constraint to the filter - * - * @param string $field The field to apply the constraint - * to. - * @param Horde_Constraint $constraint The constraint to apply. - * - * @return Horde_Log_Filter_Constraint A reference to $this to allow - * method chaining. - */ - public function addConstraint($field, Horde_Constraint $constraint) - { - if (!isset($this->_constraints[$field])) { - $this->_constraints[$field] = clone($this->_coupler); - } - $this->_constraints[$field]->addConstraint($constraint); - - return $this; - } - - /** - * Add a regular expression to filter by - * - * Takes a field name and a regex, if the regex does not match then the - * event is filtered. - * - * @param string $field The name of the field that should be part of the - * event. - * @param string $regex The regular expression to filter by. - * @return Horde_Log_Filter_Constraint A reference to $this to allow - * method chaining. - */ - public function addRegex($field, $regex) - { - return $this->addConstraint($field, new Horde_Constraint_PregMatch($regex)); - } - - /** - * Add a required field to the filter - * - * If the field does not exist on the event, then it is filtered. - * - * @param string $field The name of the field that should be part of the - * event. - * - * @return Horde_Log_Filter_Constraint A reference to $this to allow - * method chaining. - */ - public function addRequiredField($field) - { - return $this->addConstraint($field, new Horde_Constraint_Not(new Horde_Constraint_Null())); - } - - /** - * Adds all arguments passed as required fields - * - * @return Horde_Log_Filter_Constraint A reference to $this to allow - * method chaining. - */ - public function addRequiredFields() - { - foreach (func_get_args() as $f) { - $this->addRequiredField($f); - } - - return $this; - } - - /** - * Returns Horde_Log_Filter::ACCEPT to accept the message, - * Horde_Log_Filter::IGNORE to ignore it. - * - * @param array $event Log event. - * - * @return boolean accepted? - */ - public function accept($event) - { - foreach ($this->_constraints as $field => $constraint) { - $value = isset($event[$field]) ? $event[$field] : null; - if (!$constraint->evaluate($value)) { - return Horde_Log_Filter::IGNORE; - } - } - - return Horde_Log_Filter::ACCEPT; - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter/ExactLevel.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter/ExactLevel.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter/ExactLevel.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter/ExactLevel.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,50 +0,0 @@ - - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ - -/** - * @author Bryan Alves - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ -class Horde_Log_Filter_ExactLevel implements Horde_Log_Filter -{ - /** - * @var integer - */ - protected $_level; - - /** - * Filter out any log messages not equal to $level. - * - * @param integer $level Log level to pass through the filter - */ - public function __construct($level) - { - if (!is_integer($level)) { - throw new Horde_Log_Exception('Level must be an integer'); - } - - $this->_level = $level; - } - - /** - * Returns TRUE to accept the message, FALSE to block it. - * - * @param array $event Log event - * @return boolean accepted? - */ - public function accept($event) - { - return $event['level'] == $this->_level; - } -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter/Level.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter/Level.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter/Level.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter/Level.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,63 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ -class Horde_Log_Filter_Level implements Horde_Log_Filter -{ - /** - * Filter level. - * - * @var integer - */ - protected $_level; - - /** - * Filter out any log messages greater than $level. - * - * @param integer $level Maximum log level to pass through the filter. - * - * @throws InvalidArgumentException - */ - public function __construct($level) - { - if (!is_integer($level)) { - throw new InvalidArgumentException('Level must be an integer'); - } - - $this->_level = $level; - } - - /** - * Returns Horde_Log_Filter::ACCEPT to accept the message, - * Horde_Log_Filter::IGNORE to ignore it. - * - * @param array $event Log event. - * - * @return boolean Accepted? - */ - public function accept($event) - { - return ($event['level'] <= $this->_level); - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter/Message.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter/Message.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter/Message.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter/Message.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,63 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ -class Horde_Log_Filter_Message implements Horde_Log_Filter -{ - /** - * Filter regex. - * - * @var string - */ - protected $_regexp; - - /** - * Filter out any log messages not matching $regexp. - * - * @param string $regexp Regular expression to test the log message. - * - * @throws InvalidArgumentException Invalid regular expression. - */ - public function __construct($regexp) - { - if (@preg_match($regexp, '') === false) { - throw new InvalidArgumentException('Invalid regular expression ' . $regexp); - } - - $this->_regexp = $regexp; - } - - /** - * Returns Horde_Log_Filter::ACCEPT to accept the message, - * Horde_Log_Filter::IGNORE to ignore it. - * - * @param array $event Log event. - * - * @return boolean Accepted? - */ - public function accept($event) - { - return (preg_match($this->_regexp, $event['message']) > 0); - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter/Suppress.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter/Suppress.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter/Suppress.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter/Suppress.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ -class Horde_Log_Filter_Suppress implements Horde_Log_Filter -{ - /** - * Accept all events? - * - * @var boolean - */ - protected $_accept = Horde_Log_Filter::ACCEPT; - - /** - * This is a simple boolean filter. - * - * @param boolean $suppress Should all log events be suppressed? - */ - public function suppress($suppress) - { - $this->_accept = !$suppress; - } - - /** - * Returns Horde_Log_Filter::ACCEPT to accept the message, - * Horde_Log_Filter::IGNORE to ignore it. - * - * @param array $event Event data. - * - * @return boolean Accepted? - */ - public function accept($event) - { - return $this->_accept; - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Filter.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Filter.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ - -/** - * @category Horde - * @subpackage Filters - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Filters - */ -interface Horde_Log_Filter -{ - /** - * Accept a message - */ - const ACCEPT = true; - - /** - * Filter out a message - */ - const IGNORE = false; - - /** - * Returns Horde_Log_Filter::ACCEPT to accept the message, - * Horde_Log_Filter::IGNORE to ignore it. - * - * @param array $event Log event. - * - * @return boolean Accepted? - */ - public function accept($event); - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Formatter/Simple.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Formatter/Simple.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Formatter/Simple.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Formatter/Simple.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,77 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Formatters - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Formatters - */ -class Horde_Log_Formatter_Simple implements Horde_Log_Formatter -{ - /** - * Format string. - * - * @var string - */ - protected $_format; - - /** - * Constructor. - * - * @param array $options Configuration options: - *
-     * 'format' - (string) The log template.
-     * 
- * - * @throws InvalidArgumentException - */ - public function __construct($options = null) - { - $format = (is_array($options) && isset($options['format'])) - ? $options['format'] - : $options; - - if (is_null($format)) { - $format = '%timestamp% %levelName%: %message%' . PHP_EOL; - } - - if (!is_string($format)) { - throw new InvalidArgumentException('Format must be a string'); - } - - $this->_format = $format; - } - - /** - * Formats an event to be written by the handler. - * - * @param array $event Log event. - * - * @return string Formatted line. - */ - public function format($event) - { - $output = $this->_format; - foreach ($event as $name => $value) { - $output = str_replace("%$name%", $value, $output); - } - return $output; - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Formatter/Xml.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Formatter/Xml.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Formatter/Xml.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Formatter/Xml.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,69 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Formatters - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Formatters - */ -class Horde_Log_Formatter_Xml implements Horde_Log_Formatter -{ - /** - * Config options. - * - * @var array - */ - protected $_options = array( - 'elementEntry' => 'log', - 'elementTimestamp' => 'timestamp', - 'elementMessage' => 'message', - 'elementLevel' => 'level', - 'lineEnding' => PHP_EOL - ); - - /** - * Constructor. - * - * TODO - */ - public function __construct($options = array()) - { - $this->_options = array_merge($this->_options, $options); - } - - /** - * Formats an event to be written by the handler. - * - * @param array $event Log event. - * - * @return string XML string. - */ - public function format($event) - { - $dom = new DOMDocument(); - - $elt = $dom->appendChild(new DOMElement($this->_options['elementEntry'])); - $elt->appendChild(new DOMElement($this->_options['elementTimestamp'], date('c'))); - $elt->appendChild(new DOMElement($this->_options['elementMessage'], $event['message'])); - $elt->appendChild(new DOMElement($this->_options['elementLevel'], $event['level'])); - - return preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $dom->saveXML()) . $this->_options['lineEnding']; - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Formatter.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Formatter.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Formatter.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Formatter.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,34 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - */ -interface Horde_Log_Formatter -{ - /** - * Formats an event to be written by the handler. - * - * @param array $event Log event. - * - * @return string Formatted line. - */ - public function format($event); - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Base.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Base.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Base.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Base.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,99 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ -abstract class Horde_Log_Handler_Base -{ - /** - * Options. - * - * @var array - */ - protected $_options = array( - 'ident' => '' - ); - - /** - * List of filter objects. - * - * @var array - */ - protected $_filters = array(); - - /** - * Add a filter specific to this handler. - * - * @param Horde_Log_Filter $filter Filter to add. - */ - public function addFilter($filter) - { - $this->_filters[] = is_integer($filter) - ? new Horde_Log_Filter_Level($filter) - : $filter; - } - - /** - * Log a message to this handler. - * - * @param array $event Log event. - */ - public function log($event) - { - // If any local filter rejects the message, don't log it. - foreach ($this->_filters as $filter) { - if (!$filter->accept($event)) { - return; - } - } - - $this->write($event); - } - - /** - * Sets an option specific to the implementation of the log handler. - * - * @param string $optionKey Key name for the option to be changed. Keys - * are handler-specific. - * @param mixed $optionValue New value to assign to the option - * - * @return boolean True. - * @throws Horde_Log_Exception - */ - public function setOption($optionKey, $optionValue) - { - if (!isset($this->_options[$optionKey])) { - throw new Horde_Log_Exception('Unknown option "' . $optionKey . '".'); - } - $this->_options[$optionKey] = $optionValue; - - return true; - } - - /** - * Buffer a message to be stored in the storage. - * - * @param array $event Log event. - */ - abstract public function write($event); - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Firebug.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Firebug.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Firebug.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Firebug.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,139 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ -class Horde_Log_Handler_Firebug extends Horde_Log_Handler_Base -{ - /** - * Formats the log message before writing. - * - * @var Horde_Log_Formatter - */ - protected $_formatter; - - /** - * Options to be set by setOption(). - * - * @var array - */ - protected $_options = array( - 'buffering' => false, - 'ident' => '' - ); - - /** - * Array of buffered output. - * - * @var string - */ - protected $_buffer = array(); - - /** - * Mapping of log priorities to Firebug methods. - * - * @var array - */ - protected static $_methods = array( - Horde_Log::EMERG => 'error', - Horde_Log::ALERT => 'error', - Horde_Log::CRIT => 'error', - Horde_Log::ERR => 'error', - Horde_Log::WARN => 'warn', - Horde_Log::NOTICE => 'info', - Horde_Log::INFO => 'info', - Horde_Log::DEBUG => 'debug', - ); - - /** - * Class Constructor - * - * @param Horde_Log_Formatter $formatter Log formatter. - */ - public function __construct(Horde_Log_Formatter $formatter = null) - { - $this->_formatter = is_null($formatter) - ? new Horde_Log_Formatter_Simple() - : $formatter; - } - - /** - * Write a message to the firebug console. This function really just - * writes the message to the buffer. If buffering is enabled, the - * message won't be output until the buffer is flushed. If - * buffering is not enabled, the buffer will be flushed - * immediately. - * - * @param array $event Log event. - * - * @return boolean True. - */ - public function write($event) - { - if (!empty($this->_options['ident'])) { - $event['message'] = $this->_options['ident'] . ' ' . $event['message']; - } - - $this->_buffer[] = $event; - - if (empty($this->_options['buffering'])) { - $this->flush(); - } - - return true; - } - - /** - * Flush the buffer. - */ - public function flush() - { - if (!count($this->_buffer)) { - return true; - } - - $output = array(); - foreach ($this->_buffer as $event) { - $line = trim($this->_formatter->format($event)); - - // Normalize line breaks. - $line = str_replace("\r\n", "\n", $line); - - // Escape line breaks - $line = str_replace("\n", "\\n\\\n", $line); - - // Escape quotes. - $line = str_replace('"', '\\"', $line); - - // Firebug call. - $method = isset(self::$_methods[$event['level']]) - ? self::$_methods[$event['level']] - : 'log'; - $output[] = 'console.' . $method . '("' . $line . '");'; - } - - echo '\n"; - - $this->_buffer = array(); - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Mock.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Mock.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Mock.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Mock.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,59 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ -class Horde_Log_Handler_Mock extends Horde_Log_Handler_Base -{ - /** - * Log events. - * - * @var array - */ - public $events = array(); - - /** - * Was shutdown called? - * - * @var boolean - */ - public $shutdown = false; - - /** - * Write a message to the log. - * - * @param array $event Event data. - */ - public function write($event) - { - $this->events[] = $event; - } - - /** - * Record shutdown - */ - public function shutdown() - { - $this->shutdown = true; - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Null.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Null.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Null.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Null.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,37 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ -class Horde_Log_Handler_Null extends Horde_Log_Handler_Base -{ - /** - * Write a message to the log buffer. - * - * @return boolean True. - */ - public function write($event) - { - return true; - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Scribe.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Scribe.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Scribe.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Scribe.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,90 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ -class Horde_Log_Handler_Scribe extends Horde_Log_Handler_Base -{ - /** - * Scribe client. - * - * @var Horde_Scribe_Client - */ - protected $_scribe; - - /** - * Formats the log message before writing. - * - * @var Horde_Log_Formatter - */ - protected $_formatter; - - /** - * Options to be set by setOption(). - * - * @var array - */ - protected $_options = array( - 'addNewline' => false, - 'category' => 'default', - 'ident' => '' - ); - - /** - * Constructor. - * - * @param Horde_Scribe_Client $scribe Scribe client. - * @param Horde_Log_Formatter $formatter Log formatter. - */ - public function __construct(Horde_Scribe_Client $scribe, - Horde_Log_Formatter $formatter = null) - { - $this->_formatter = is_null($formatter) - ? new Horde_Log_Formatter_Simple() - : $formatter; - $this->_scribe = $scribe; - } - - /** - * Write a message to the log. - * - * @param array $event Log event. - * - * @return boolean True. - */ - public function write($event) - { - if (!empty($this->_options['ident'])) { - $event['message'] = $this->_options['ident'] . ' ' . $event['message']; - } - - $category = isset($event['category']) - ? $event['category'] - : $this->_options['category']; - - $message = $this->_formatter->format($event); - if (!$this->_options['addNewline']) { - $message = rtrim($message); - } - - $this->_scribe->log($category, $message); - - return true; - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Stream.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Stream.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Stream.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Stream.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,124 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ -class Horde_Log_Handler_Stream extends Horde_Log_Handler_Base -{ - /** - * Formats the log message before writing. - * - * @var Horde_Log_Formatter - */ - protected $_formatter; - - /** - * Holds the PHP stream to log to. - * - * @var null|stream - */ - protected $_stream = null; - - /** - * The open mode. - * - * @var string - */ - protected $_mode; - - /** - * The stream to open. - * - * @var string - */ - protected $_streamOrUrl; - - /** - * Class Constructor - * - * @param mixed $streamOrUrl Stream or URL to open as a - * stream. - * @param string $mode Mode, only applicable if a URL - * is given. - * @param Horde_Log_Formatter $formatter Log formatter. - * - * @throws Horde_Log_Exception - */ - public function __construct($streamOrUrl, $mode = 'a+', - Horde_Log_Formatter $formatter = null) - { - $this->_formatter = is_null($formatter) - ? new Horde_Log_Formatter_Simple() - : $formatter; - $this->_mode = $mode; - $this->_streamOrUrl = $streamOrUrl; - - if (is_resource($streamOrUrl)) { - if (get_resource_type($streamOrUrl) != 'stream') { - throw new Horde_Log_Exception(__CLASS__ . ': Resource is not a stream'); - } - - if ($mode && $mode != 'a+') { - throw new Horde_Log_Exception(__CLASS__ . ': Mode cannot be changed on existing streams'); - } - - $this->_stream = $streamOrUrl; - } else { - $this->__wakeup(); - } - } - - /** - * Wakup function - reattaches stream. - * - * @throws Horde_Log_Exception - */ - public function __wakeup() - { - if (!($this->_stream = @fopen($this->_streamOrUrl, $this->_mode, false))) { - throw new Horde_Log_Exception(__CLASS__ . ': "' . $this->_streamOrUrl . '" cannot be opened with mode "' . $this->_mode . '"'); - } - } - - /** - * Write a message to the log. - * - * @param array $event Log event. - * - * @return boolean True. - * @throws Horde_Log_Exception - */ - public function write($event) - { - if (!empty($this->_options['ident'])) { - $event['message'] = $this->_options['ident'] . ' ' . $event['message']; - } - $line = $this->_formatter->format($event); - - if (!@fwrite($this->_stream, $line)) { - throw new Horde_Log_Exception(__CLASS__ . ': Unable to write to stream'); - } - - return true; - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Syslog.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Syslog.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Handler/Syslog.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Handler/Syslog.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,121 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage Handlers - */ -class Horde_Log_Handler_Syslog extends Horde_Log_Handler_Base -{ - /** - * Options to be set by setOption(). - * Sets openlog and syslog options. - * - * @var array - */ - protected $_options = array( - 'defaultPriority' => LOG_ERR, - 'facility' => LOG_USER, - 'ident' => false, - 'openlogOptions' => false - ); - - /** - * Last ident set by a syslog-handler instance. - * - * @var string - */ - protected $_lastIdent; - - /** - * Last facility name set by a syslog-handler instance. - * - * @var string - */ - protected $_lastFacility; - - /** - * Map of log levels to syslog priorities. - * - * @var array - */ - protected $_priorities = array( - Horde_Log::EMERG => LOG_EMERG, - Horde_Log::ALERT => LOG_ALERT, - Horde_Log::CRIT => LOG_CRIT, - Horde_Log::ERR => LOG_ERR, - Horde_Log::WARN => LOG_WARNING, - Horde_Log::NOTICE => LOG_NOTICE, - Horde_Log::INFO => LOG_INFO, - Horde_Log::DEBUG => LOG_DEBUG, - ); - - /** - * Write a message to the log. - * - * @param array $event Log event. - * - * @return boolean True. - * @throws Horde_Log_Exception - */ - public function write($event) - { - if (($this->_options['ident'] !== $this->_lastIdent) || - ($this->_options['facility'] !== $this->_lastFacility)) { - $this->_initializeSyslog(); - } - - $priority = $this->_toSyslog($event['level']); - if (!syslog($priority, $event['message'])) { - throw new Horde_Log_Exception('Unable to log message'); - } - - return true; - } - - /** - * Translate a log level to a syslog LOG_* priority. - * - * @param integer $level Log level. - * - * @return integer A LOG_* constant. - */ - protected function _toSyslog($level) - { - return isset($this->_priorities[$level]) - ? $this->_priorities[$level] - : $this->_options['defaultPriority']; - } - - /** - * Initialize syslog / set ident and facility. - * - * @param string $ident Ident. - * @param string $facility Syslog facility. - * - * @throws Horde_Log_Exception - */ - protected function _initializeSyslog() - { - $this->_lastIdent = $this->_options['ident']; - $this->_lastFacility = $this->_options['facility']; - - if (!openlog($this->_options['ident'], $this->_options['openlogOptions'], $this->_options['facility'])) { - throw new Horde_Log_Exception('Unable to open syslog'); - } - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Logger.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Logger.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log/Logger.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log/Logger.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,253 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * - * @method void LOGLEVEL() LOGLEVEL($event) Log an event at LOGLEVEL, where LOGLEVEL has been added with addLevel() or already exists - * @method void emerg() emerg($event) Log an event at the EMERG log level - * @method void alert() alert($event) Log an event at the ALERT log level - * @method void crit() crit($event) Log an event at the CRIT log level - * @method void err() err($event) Log an event at the ERR log level - * @method void warn() warn($event) Log an event at the WARN log level - * @method void notice() notice($event) Log an event at the NOTICE log level - * @method void info() info($event) Log an event at the INFO log level - * @method void debug() debug($event) Log an event at the DEBUG log level - */ -class Horde_Log_Logger implements Serializable -{ - /* Serialize version. */ - const VERSION = 1; - - /** - * Log levels where the keys are the level priorities and the values are - * the level names. - * - * @var array - */ - private $_levels = array(); - - /** - * Horde_Log_Handler_Base objects. - * - * @var array - */ - private $_handlers = array(); - - /** - * Horde_Log_Filter objects. - * - * @var array - */ - private $_filters = array(); - - /** - * Constructor. - * - * @param Horde_Log_Handler_Base|null $handler Default handler. - */ - public function __construct($handler = null) - { - if (!is_null($handler)) { - $this->addHandler($handler); - } - - $this->_init(); - } - - /** - * Serialize. - * - * @return string Serialized representation of this object. - */ - public function serialize() - { - return serialize(array( - self::VERSION, - $this->_filters, - $this->_handlers - )); - } - - /** - * Unserialize. - * - * @param string $data Serialized data. - * - * @throws Exception - */ - public function unserialize($data) - { - $data = @unserialize($data); - if (!is_array($data) || - !isset($data[0]) || - ($data[0] != self::VERSION)) { - throw new Exception('Cache version change'); - } - - $this->_filters = $data[1]; - $this->_handlers = $data[2]; - - $this->_init(); - } - - /** - * Initialization tasks. - */ - protected function _init() - { - $r = new ReflectionClass('Horde_Log'); - $this->_levels = array_flip($r->getConstants()); - } - - /** - * Undefined method handler allows a shortcut: - *
-     * $log->levelName('message');
-     *   instead of
-     * $log->log('message', Horde_Log_LEVELNAME);
-     * 
- * - * @param string $method Log level name. - * @param string $params Message to log. - */ - public function __call($method, $params) - { - $levelName = strtoupper($method); - if (($level = array_search($levelName, $this->_levels)) !== false) { - $this->log(array_shift($params), $level); - } else { - throw new Horde_Log_Exception('Bad log level ' . $levelName); - } - } - - /** - * Log a message at a level - * - * @param mixed $event Message to log, either an array or a string. - * @param integer $level Log level of message, required if $message is a - * string. - */ - public function log($event, $level = null) - { - if (empty($this->_handlers)) { - throw new Horde_Log_Exception('No handlers were added'); - } - - // Create an event array from the given arguments. - if (is_array($event)) { - // If we are passed an array, it must contain 'message' - // and 'level' indices. - if (!isset($event['message'])) { - throw new Horde_Log_Exception('Event array did not contain a message'); - } - if (!isset($event['level'])) { - if (is_null($level)) { - throw new Horde_Log_Exception('Event array did not contain a log level'); - } - $event['level'] = $level; - } - } else { - // Create an event array from the message and level - // arguments. - $event = array('message' => $event, 'level' => $level); - } - - if (!isset($this->_levels[$event['level']]) || - !is_string($this->_levels[$event['level']])) { - throw new Horde_Log_Exception('Bad log level: ' . $event['level']); - } - - // Fill in the level name and timestamp for filters, formatters, - // handlers. - $event['levelName'] = $this->_levels[$event['level']]; - - if (!isset($event['timestamp'])) { - $event['timestamp'] = date('c'); - } - - // If any global filter rejects the event, don't log it. - foreach ($this->_filters as $filter) { - if (!$filter->accept($event)) { - return; - } - } - - foreach ($this->_handlers as $handler) { - $handler->log($event); - } - } - - /** - * Does this logger have the level $name already? - * - * @param string $name The level name to check for. - * - * @return boolean Whether the logger already has the specific level - * name. - */ - public function hasLevel($name) - { - return (boolean)array_search($name, $this->_levels); - } - - /** - * Add a custom log level - * - * @param string $name Name of level. - * @param integer $level Numeric level. - */ - public function addLevel($name, $level) - { - // Log level names must be uppercase for predictability. - $name = strtoupper($name); - - if (isset($this->_levels[$level]) || $this->hasLevel($name)) { - throw new Horde_Log_Exception('Existing log levels cannot be overwritten'); - } - - $this->_levels[$level] = $name; - } - - /** - * Add a filter that will be applied before all log handlers. - * Before a message will be received by any of the handlers, it - * must be accepted by all filters added with this method. - * - * @param Horde_Log_Filter $filter Filter to add. - */ - public function addFilter($filter) - { - $this->_filters[] = is_integer($filter) - ? new Horde_Log_Filter_Level($filter) - : $filter; - } - - /** - * Add a handler. A handler is responsible for taking a log - * message and writing it out to storage. - * - * @param Horde_Log_Handler_Base $handler Handler to add. - */ - public function addHandler($handler) - { - $this->_handlers[] = $handler; - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log.php php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/lib/Horde/Log.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/lib/Horde/Log.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,46 +0,0 @@ - - * @author Chuck Hagenbuch - * @license http://www.horde.org/licenses/bsd BSD - */ - -/** - * @category Horde - * @package Log - */ -class Horde_Log { - - /** Emergency: system is unusable */ - const EMERG = 0; - - /** Alert: action must be taken immediately */ - const ALERT = 1; - - /** Critical: critical conditions */ - const CRIT = 2; - - /** Error: error conditions */ - const ERR = 3; - - /** Warning: warning conditions */ - const WARN = 4; - - /** Notice: normal but significant condition */ - const NOTICE = 5; - - /** Informational: informational messages */ - const INFO = 6; - - /** Debug: debug-level messages */ - const DEBUG = 7; - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/AllTests.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/AllTests.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/AllTests.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/AllTests.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ -run(); diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/ChainingTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/ChainingTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/ChainingTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/ChainingTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,79 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Filter_ChainingTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - date_default_timezone_set('America/New_York'); - - $this->log = fopen('php://memory', 'w'); - $this->logger = new Horde_Log_Logger(); - $this->logger->addHandler(new Horde_Log_Handler_Stream($this->log)); - } - - public function tearDown() - { - fclose($this->log); - } - - public function testFilterAllHandlers() - { - // filter out anything above a WARNing for all handlers - $this->logger->addFilter(Horde_Log::WARN); - - $this->logger->info($ignored = 'info-message-ignored'); - $this->logger->warn($logged = 'warn-message-logged'); - - rewind($this->log); - $logdata = stream_get_contents($this->log); - - $this->assertNotContains($ignored, $logdata); - $this->assertContains($logged, $logdata); - } - - - public function testFilterOnSpecificHandler() - { - $log2 = fopen('php://memory', 'w'); - $handler2 = new Horde_Log_Handler_Stream($log2); - $handler2->addFilter(Horde_Log::ERR); - - $this->logger->addHandler($handler2); - - $this->logger->warn($warn = 'warn-message'); - $this->logger->err($err = 'err-message'); - - rewind($this->log); - $logdata = stream_get_contents($this->log); - $this->assertContains($warn, $logdata); - $this->assertContains($err, $logdata); - - rewind($log2); - $logdata = stream_get_contents($log2); - $this->assertContains($err, $logdata); - $this->assertNotContains($warn, $logdata); - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/ConstraintTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/ConstraintTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/ConstraintTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/ConstraintTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,111 +0,0 @@ - - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author James Pepin - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Filter_ConstraintTest extends Horde_Test_Case -{ - public function testFilterDoesNotAcceptWhenRequiredFieldIsMissing() - { - $event = array( - 'someotherfield' => 'other value', - ); - $filterator = new Horde_Log_Filter_Constraint(); - $filterator->addRequiredField('required_field'); - - $this->assertFalse($filterator->accept($event)); - } - - public function testFilterAcceptsWhenRequiredFieldisPresent() - { - $event = array( - 'required_field' => 'somevalue', - 'someotherfield' => 'other value', - ); - $filterator = new Horde_Log_Filter_Constraint(); - $filterator->addRequiredField('required_field'); - - $this->assertTrue($filterator->accept($event)); - } - - public function testFilterAcceptsWhenRegexMatchesField() - { - $event = array( - 'regex_field' => 'somevalue', - 'someotherfield' => 'other value', - ); - $filterator = new Horde_Log_Filter_Constraint(); - $filterator->addRegex('regex_field', '/somevalue/'); - - $this->assertTrue($filterator->accept($event)); - } - - public function testFilterAcceptsWhenRegex_DOESNOT_MatcheField() - { - $event = array( - 'regex_field' => 'somevalue', - 'someotherfield' => 'other value', - ); - $filterator = new Horde_Log_Filter_Constraint(); - $filterator->addRegex('regex_field', '/someothervalue/'); - - $this->assertFalse($filterator->accept($event)); - } - - private function getConstraintMock($returnVal) - { - $const = $this->getMock('Horde_Constraint', array('evaluate')); - $const->expects($this->once()) - ->method('evaluate') - ->will($this->returnValue($returnVal)); - return $const; - } - - public function testFilterCallsEvalOnAllConstraintsWhenTheyAreAllTrue() - { - $filterator = new Horde_Log_Filter_Constraint(); - $filterator->addConstraint('fieldname', $this->getConstraintMock(true)); - $filterator->addConstraint('fieldname', $this->getConstraintMock(true)); - - $filterator->accept(array('fieldname' => 'foo')); - } - - public function testFilterStopsWhenItFindsAFalseCondition() - { - $filterator = new Horde_Log_Filter_Constraint(); - $filterator->addConstraint('fieldname', $this->getConstraintMock(true)); - $filterator->addConstraint('fieldname', $this->getConstraintMock(true)); - $filterator->addConstraint('fieldname', new Horde_Constraint_AlwaysFalse()); - - $const = $this->getMock('Horde_Constraint', array('evaluate')); - $const->expects($this->never()) - ->method('evaluate'); - $filterator->addConstraint('fieldname', $const); - $filterator->accept(array('fieldname' => 'foo')); - - } - - public function testFilterAcceptCallsConstraintOnNullWhenFieldDoesnotExist() - { - $filterator = new Horde_Log_Filter_Constraint(); - $const = $this->getMock('Horde_Constraint', array('evaluate')); - $const->expects($this->once()) - ->method('evaluate') - ->with(null); - $filterator->addConstraint('fieldname', $const); - $filterator->accept(array('someotherfield' => 'foo')); - } -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/ExactLevelTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/ExactLevelTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/ExactLevelTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/ExactLevelTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Filter_ExactLevelTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - // accept at and only at level 2 - $this->filter = new Horde_Log_Filter_ExactLevel(2); - } - - public function testLevelFilterAccept() - { - $this->assertTrue($this->filter->accept(array('message' => '', 'level' => 2))); - } - - public function testLevelFilterReject() - { - $this->assertFalse($this->filter->accept(array('message' => '', 'level' => 1))); - $this->assertFalse($this->filter->accept(array('message' => '', 'level' => 3))); - } - - public function testConstructorThrowsOnInvalidLevel() - { - try { - new Horde_Log_Filter_Level('foo'); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('InvalidArgumentException', $e); - $this->assertRegExp('/must be an integer/i', $e->getMessage()); - } - } -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/LevelTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/LevelTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/LevelTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/LevelTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,54 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Filter_LevelTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - // accept at or below level 2 - $this->filter = new Horde_Log_Filter_Level(2); - } - - public function testLevelFilterAccept() - { - $this->assertTrue($this->filter->accept(array('message' => '', 'level' => 2))); - $this->assertTrue($this->filter->accept(array('message' => '', 'level' => 1))); - } - - public function testLevelFilterReject() - { - $this->assertFalse($this->filter->accept(array('message' => '', 'level' => 3))); - } - - public function testConstructorThrowsOnInvalidLevel() - { - try { - new Horde_Log_Filter_Level('foo'); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('InvalidArgumentException', $e); - $this->assertRegExp('/must be an integer/i', $e->getMessage()); - } - } -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/MessageTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/MessageTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/MessageTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/MessageTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,45 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Filter_MessageTest extends PHPUnit_Framework_TestCase -{ - - public function testMessageFilterRecognizesInvalidRegularExpression() - { - try { - $filter = new Horde_Log_Filter_Message('invalid regexp'); - $this->fail(); - } catch (InvalidArgumentException $e) { - $this->assertRegexp('/invalid reg/i', $e->getMessage()); - } - } - - public function testMessageFilter() - { - $filter = new Horde_Log_Filter_Message('/accept/'); - $this->assertTrue($filter->accept(array('message' => 'foo accept bar', 'level' => 0))); - $this->assertFalse($filter->accept(array('message' => 'foo reject bar', 'level' => 0))); - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/SuppressTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/SuppressTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Filter/SuppressTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Filter/SuppressTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,60 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Filter_SuppressTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - $this->filter = new Horde_Log_Filter_Suppress(); - } - - public function testSuppressIsInitiallyOff() - { - $this->assertTrue($this->filter->accept(array())); - } - - public function testSuppressOn() - { - $this->filter->suppress(true); - $this->assertFalse($this->filter->accept(array())); - $this->assertFalse($this->filter->accept(array())); - } - - public function testSuppressOff() - { - $this->filter->suppress(false); - $this->assertTrue($this->filter->accept(array())); - $this->assertTrue($this->filter->accept(array())); - } - - public function testSuppressCanBeReset() - { - $this->filter->suppress(true); - $this->assertFalse($this->filter->accept(array())); - $this->filter->suppress(false); - $this->assertTrue($this->filter->accept(array())); - $this->filter->suppress(true); - $this->assertFalse($this->filter->accept(array())); - } -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Formatter/SimpleTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Formatter/SimpleTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Formatter/SimpleTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Formatter/SimpleTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,48 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Formatter_SimpleTest extends PHPUnit_Framework_TestCase -{ - public function testConstructorThrowsOnBadFormatString() - { - try { - new Horde_Log_Formatter_Simple(1); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('InvalidArgumentException', $e); - $this->assertRegExp('/must be a string/i', $e->getMessage()); - } - } - - public function testDefaultFormat() - { - $f = new Horde_Log_Formatter_Simple(); - $line = $f->format(array('message' => $message = 'message', - 'level' => $level = Horde_Log::ALERT, - 'levelName' => $levelName = 'ALERT')); - - $this->assertContains($message, $line); - $this->assertContains($levelName, $line); - } -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Formatter/XmlTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Formatter/XmlTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Formatter/XmlTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Formatter/XmlTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,55 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - */ -class Horde_Log_Formatter_XmlTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - date_default_timezone_set('America/New_York'); - } - - public function testDefaultFormat() - { - $f = new Horde_Log_Formatter_Xml(); - $line = $f->format(array('message' => $message = 'message', 'level' => $level = 1)); - - $this->assertContains($message, $line); - $this->assertContains((string)$level, $line); - } - - public function testXmlDeclarationIsStripped() - { - $f = new Horde_Log_Formatter_Xml(); - $line = $f->format(array('message' => $message = 'message', 'level' => $level = 1)); - - $this->assertNotContains('<\?xml version=', $line); - } - - public function testXmlValidates() - { - $f = new Horde_Log_Formatter_Xml(); - $line = $f->format(array('message' => $message = 'message', 'level' => $level = 1)); - - $sxml = @simplexml_load_string($line); - $this->assertInstanceOf('SimpleXMLElement', $sxml, 'Formatted XML is invalid'); - } -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Handler/FirebugTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Handler/FirebugTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Handler/FirebugTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Handler/FirebugTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Handler_FirebugTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - date_default_timezone_set('America/New_York'); - } - - public function testSettingBadOptionThrows() - { - try { - $handler = new Horde_Log_Handler_Stream('php://memory'); - $handler->setOption('foo', 42); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('Horde_Log_Exception', $e); - $this->assertRegExp('/unknown option/i', $e->getMessage()); - } - } - - public function testWrite() - { - ob_start(); - - $handler = new Horde_Log_Handler_Firebug(); - $handler->write(array('message' => $message = 'message-to-log', - 'level' => $level = Horde_Log::ALERT, - 'levelName' => $levelName = 'ALERT', - 'timestamp' => date('c'))); - - $contents = ob_get_clean(); - - $date = '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}-\d{2}:\d{2}'; - - $this->assertRegExp("/console.error\(\"$date $levelName: $message\"\);/", $contents); - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Handler/NullTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Handler/NullTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Handler/NullTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Handler/NullTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,32 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Handler_NullTest extends PHPUnit_Framework_TestCase -{ - public function testWrite() - { - $handler = new Horde_Log_Handler_Null(); - $this->assertTrue($handler->write(array('message' => 'foo', 'level' => 42))); - } -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Handler/StreamTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Handler/StreamTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/Handler/StreamTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/Handler/StreamTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,125 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_Handler_StreamTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - date_default_timezone_set('America/New_York'); - } - - public function testConstructorThrowsWhenResourceIsNotStream() - { - $resource = xml_parser_create(); - try { - new Horde_Log_Handler_Stream($resource); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('Horde_Log_Exception', $e); - $this->assertRegExp('/not a stream/i', $e->getMessage()); - } - xml_parser_free($resource); - } - - public function testConstructorWithValidStream() - { - $stream = fopen('php://memory', 'a'); - new Horde_Log_Handler_Stream($stream); - } - - public function testConstructorWithValidUrl() - { - new Horde_Log_Handler_Stream('php://memory'); - } - - public function testConstructorThrowsWhenModeSpecifiedForExistingStream() - { - $stream = fopen('php://memory', 'a'); - try { - new Horde_Log_Handler_Stream($stream, 'w'); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('Horde_Log_Exception', $e); - $this->assertRegExp('/existing stream/i', $e->getMessage()); - } - } - - public function testConstructorThrowsWhenStreamCannotBeOpened() - { - try { - new Horde_Log_Handler_Stream(''); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('Horde_Log_Exception', $e); - $this->assertRegExp('/cannot be opened/i', $e->getMessage()); - } - } - - public function testSettingBadOptionThrows() - { - try { - $handler = new Horde_Log_Handler_Stream('php://memory'); - $handler->setOption('foo', 42); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('Horde_Log_Exception', $e); - $this->assertRegExp('/unknown option/i', $e->getMessage()); - } - } - - public function testWrite() - { - $stream = fopen('php://memory', 'a'); - - $handler = new Horde_Log_Handler_Stream($stream); - $handler->write(array('message' => $message = 'message-to-log', - 'level' => $level = Horde_Log::ALERT, - 'levelName' => $levelName = 'ALERT', - 'timestamp' => date('c'))); - - rewind($stream); - $contents = stream_get_contents($stream); - fclose($stream); - - $date = '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}-\d{2}:\d{2}'; - - $this->assertRegExp("/$date $levelName: $message/", $contents); - } - - public function testWriteThrowsWhenStreamWriteFails() - { - $stream = fopen('php://memory', 'a'); - $handler = new Horde_Log_Handler_Stream($stream); - fclose($stream); - - try { - $handler->write(array('message' => 'foo', 'level' => 1)); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('Horde_Log_Exception', $e); - $this->assertRegExp('/unable to write/i', $e->getMessage()); - } - } - -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/LogTest.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/LogTest.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/LogTest.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/LogTest.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,147 +0,0 @@ - - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ - -/** - * @author Mike Naberezny - * @author Chuck Hagenbuch - * @category Horde - * @license http://www.horde.org/licenses/bsd BSD - * @package Log - * @subpackage UnitTests - */ -class Horde_Log_LogTest extends PHPUnit_Framework_TestCase -{ - public function setUp() - { - date_default_timezone_set('America/New_York'); - - $this->log = fopen('php://memory', 'a'); - $this->handler = new Horde_Log_Handler_Stream($this->log); - } - - // Handlers - - public function testHandlerCanBeAddedWithConstructor() - { - $logger = new Horde_Log_Logger($this->handler); - $logger->log($message = 'message-to-long', Horde_Log::INFO); - - rewind($this->log); - $this->assertContains($message, stream_get_contents($this->log)); - } - - public function testaddHandler() - { - $logger = new Horde_Log_Logger(); - $logger->addHandler($this->handler); - $logger->log($message = 'message-to-log', Horde_Log::INFO); - - rewind($this->log); - $this->assertContains($message, stream_get_contents($this->log)); - } - - public function testaddHandlerAddsMultipleHandlers() - { - $logger = new Horde_Log_Logger(); - - // create handlers for two separate streams of temporary memory - $log1 = fopen('php://memory', 'a'); - $handler1 = new Horde_Log_Handler_Stream($log1); - $log2 = fopen('php://memory', 'a'); - $handler2 = new Horde_Log_Handler_Stream($log2); - - // add the handlers - $logger->addHandler($handler1); - $logger->addHandler($handler2); - - // log to both handlers - $logger->log($message = 'message-sent-to-both-logs', Horde_Log::INFO); - - // verify both handlers were called by the logger - rewind($log1); - $this->assertContains($message, stream_get_contents($log1)); - rewind($log2); - $this->assertContains($message, stream_get_contents($log2)); - - // prove the two memory streams are different - // and both handlers were indeed called - fwrite($log1, 'foo'); - $this->assertNotEquals(ftell($log1), ftell($log2)); - } - - public function testLoggerThrowsWhenNoHandlers() - { - $logger = new Horde_Log_Logger(); - try { - $logger->log('message', Horde_Log::INFO); - $this->fail(); - } catch (Horde_Log_Exception $e) { - $this->assertRegexp('/no handler/i', $e->getMessage()); - } - } - - // Levels - - public function testLogThrowsOnBadLogLevel() - { - $logger = new Horde_Log_Logger($this->handler); - try { - $logger->log('foo', 42); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('Horde_Log_Exception', $e); - $this->assertRegExp('/bad log level/i', $e->getMessage()); - } - } - - public function testLogThrough__callThrowsOnBadLogLevel() - { - $logger = new Horde_Log_Logger($this->handler); - try { - $logger->nonexistantLevel(''); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('Horde_Log_Exception', $e); - $this->assertRegExp('/bad log level/i', $e->getMessage()); - } - } - - public function testAddingLevelThrowsWhenOverridingBuiltinLogLevel() - { - try { - $logger = new Horde_Log_Logger($this->handler); - $logger->addLevel('BOB', 0); - $this->fail(); - } catch (Exception $e) { - $this->assertInstanceOf('Horde_Log_Exception', $e); - $this->assertRegExp('/existing log level/i', $e->getMessage()); - } - - } - - public function testAddLogLevel() - { - $logger = new Horde_Log_Logger($this->handler); - $logger->addLevel($levelName = 'EIGHT', $level = 8); - - $logger->eight($message = 'eight message'); - - rewind($this->log); - $logdata = stream_get_contents($this->log); - $this->assertContains($levelName, $logdata); - $this->assertContains($message, $logdata); - } -} diff -Nru php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/bootstrap.php php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/bootstrap.php --- php-horde-log-2.0.1/Horde_Log-2.0.1/test/Horde/Log/bootstrap.php 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.0.1/test/Horde/Log/bootstrap.php 1970-01-01 00:00:00.000000000 +0000 @@ -1,3 +0,0 @@ - diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/doc/Horde/Log/COPYING php-horde-log-2.1.0/Horde_Log-2.1.0/doc/Horde/Log/COPYING --- php-horde-log-2.0.1/Horde_Log-2.1.0/doc/Horde/Log/COPYING 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/doc/Horde/Log/COPYING 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,24 @@ + Copyright 1999-2013 Horde LLC. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE HORDE PROJECT +OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Exception.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Exception.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Exception.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Exception.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,25 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + */ +class Horde_Log_Exception extends Horde_Exception_Wrapped +{ +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter/Constraint.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter/Constraint.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter/Constraint.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter/Constraint.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,143 @@ + + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ + +/** + * Filters log events using defined constraints on one or more fields of the + * $event array. + * + * @author James Pepin + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + * + * @todo Implement constraint objects for the different types of filtering ie + * regex,required,type..etc.. so we can add different constaints ad infinitum. + */ +class Horde_Log_Filter_Constraint implements Horde_Log_Filter +{ + /** + * Constraint list. + * + * @var array + */ + protected $_constraints = array(); + + /** + * Default constraint coupler. + * + * @var Horde_Constraint_Coupler + * @default Horde_Constraint_And + */ + protected $_coupler; + + /** + * Constructor + * + * @param Horde_Constraint_Coupler $coupler The default kind of + * constraint to use to couple + * multiple constraints. + * Defaults to And. + */ + public function __construct(Horde_Constraint_Coupler $coupler = null) + { + $this->_coupler = is_null($coupler) + ? new Horde_Constraint_And() + : $coupler; + } + + /** + * Add a constraint to the filter + * + * @param string $field The field to apply the constraint + * to. + * @param Horde_Constraint $constraint The constraint to apply. + * + * @return Horde_Log_Filter_Constraint A reference to $this to allow + * method chaining. + */ + public function addConstraint($field, Horde_Constraint $constraint) + { + if (!isset($this->_constraints[$field])) { + $this->_constraints[$field] = clone($this->_coupler); + } + $this->_constraints[$field]->addConstraint($constraint); + + return $this; + } + + /** + * Add a regular expression to filter by + * + * Takes a field name and a regex, if the regex does not match then the + * event is filtered. + * + * @param string $field The name of the field that should be part of the + * event. + * @param string $regex The regular expression to filter by. + * @return Horde_Log_Filter_Constraint A reference to $this to allow + * method chaining. + */ + public function addRegex($field, $regex) + { + return $this->addConstraint($field, new Horde_Constraint_PregMatch($regex)); + } + + /** + * Add a required field to the filter + * + * If the field does not exist on the event, then it is filtered. + * + * @param string $field The name of the field that should be part of the + * event. + * + * @return Horde_Log_Filter_Constraint A reference to $this to allow + * method chaining. + */ + public function addRequiredField($field) + { + return $this->addConstraint($field, new Horde_Constraint_Not(new Horde_Constraint_Null())); + } + + /** + * Adds all arguments passed as required fields + * + * @return Horde_Log_Filter_Constraint A reference to $this to allow + * method chaining. + */ + public function addRequiredFields() + { + foreach (func_get_args() as $f) { + $this->addRequiredField($f); + } + + return $this; + } + + /** + * Returns Horde_Log_Filter::ACCEPT to accept the message, + * Horde_Log_Filter::IGNORE to ignore it. + * + * @param array $event Log event. + * + * @return boolean accepted? + */ + public function accept($event) + { + foreach ($this->_constraints as $field => $constraint) { + $value = isset($event[$field]) ? $event[$field] : null; + if (!$constraint->evaluate($value)) { + return Horde_Log_Filter::IGNORE; + } + } + + return Horde_Log_Filter::ACCEPT; + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter/ExactLevel.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter/ExactLevel.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter/ExactLevel.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter/ExactLevel.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,50 @@ + + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ + +/** + * @author Bryan Alves + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ +class Horde_Log_Filter_ExactLevel implements Horde_Log_Filter +{ + /** + * @var integer + */ + protected $_level; + + /** + * Filter out any log messages not equal to $level. + * + * @param integer $level Log level to pass through the filter + */ + public function __construct($level) + { + if (!is_integer($level)) { + throw new Horde_Log_Exception('Level must be an integer'); + } + + $this->_level = $level; + } + + /** + * Returns TRUE to accept the message, FALSE to block it. + * + * @param array $event Log event + * @return boolean accepted? + */ + public function accept($event) + { + return $event['level'] == $this->_level; + } +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter/Level.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter/Level.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter/Level.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter/Level.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,63 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ +class Horde_Log_Filter_Level implements Horde_Log_Filter +{ + /** + * Filter level. + * + * @var integer + */ + protected $_level; + + /** + * Filter out any log messages greater than $level. + * + * @param integer $level Maximum log level to pass through the filter. + * + * @throws InvalidArgumentException + */ + public function __construct($level) + { + if (!is_integer($level)) { + throw new InvalidArgumentException('Level must be an integer'); + } + + $this->_level = $level; + } + + /** + * Returns Horde_Log_Filter::ACCEPT to accept the message, + * Horde_Log_Filter::IGNORE to ignore it. + * + * @param array $event Log event. + * + * @return boolean Accepted? + */ + public function accept($event) + { + return ($event['level'] <= $this->_level); + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter/Message.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter/Message.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter/Message.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter/Message.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,63 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ +class Horde_Log_Filter_Message implements Horde_Log_Filter +{ + /** + * Filter regex. + * + * @var string + */ + protected $_regexp; + + /** + * Filter out any log messages not matching $regexp. + * + * @param string $regexp Regular expression to test the log message. + * + * @throws InvalidArgumentException Invalid regular expression. + */ + public function __construct($regexp) + { + if (@preg_match($regexp, '') === false) { + throw new InvalidArgumentException('Invalid regular expression ' . $regexp); + } + + $this->_regexp = $regexp; + } + + /** + * Returns Horde_Log_Filter::ACCEPT to accept the message, + * Horde_Log_Filter::IGNORE to ignore it. + * + * @param array $event Log event. + * + * @return boolean Accepted? + */ + public function accept($event) + { + return (preg_match($this->_regexp, $event['message']) > 0); + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter/Suppress.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter/Suppress.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter/Suppress.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter/Suppress.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,57 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ +class Horde_Log_Filter_Suppress implements Horde_Log_Filter +{ + /** + * Accept all events? + * + * @var boolean + */ + protected $_accept = Horde_Log_Filter::ACCEPT; + + /** + * This is a simple boolean filter. + * + * @param boolean $suppress Should all log events be suppressed? + */ + public function suppress($suppress) + { + $this->_accept = !$suppress; + } + + /** + * Returns Horde_Log_Filter::ACCEPT to accept the message, + * Horde_Log_Filter::IGNORE to ignore it. + * + * @param array $event Event data. + * + * @return boolean Accepted? + */ + public function accept($event) + { + return $this->_accept; + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Filter.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Filter.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,48 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ + +/** + * @category Horde + * @subpackage Filters + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Filters + */ +interface Horde_Log_Filter +{ + /** + * Accept a message + */ + const ACCEPT = true; + + /** + * Filter out a message + */ + const IGNORE = false; + + /** + * Returns Horde_Log_Filter::ACCEPT to accept the message, + * Horde_Log_Filter::IGNORE to ignore it. + * + * @param array $event Log event. + * + * @return boolean Accepted? + */ + public function accept($event); + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Cli.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Cli.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Cli.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Cli.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,76 @@ + + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ + +/** + * Formatter for the command line interface using Horde_Cli. + * + * @author Jan Schneider + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Formatters + */ +class Horde_Log_Formatter_Cli implements Horde_Log_Formatter +{ + /** + * A CLI handler. + * + * @var Horde_Cli + */ + protected $_cli; + + /** + * Constructor. + * + * @param Horde_Cli $cli A Horde_Cli instance. + */ + public function __construct(Horde_Cli $cli) + { + $this->_cli = $cli; + } + + /** + * Formats an event to be written by the handler. + * + * @param array $event Log event. + * + * @return string Formatted line. + */ + public function format($event) + { + $flag = '['. str_pad($event['levelName'], 7, ' ', STR_PAD_BOTH) . '] '; + + switch ($event['level']) { + case Horde_Log::EMERG: + case Horde_Log::ALERT: + case Horde_Log::CRIT: + case Horde_Log::ERR: + $type_message = $this->_cli->red($flag); + break; + + case Horde_Log::WARN: + case Horde_Log::NOTICE: + $type_message = $this->_cli->yellow($flag); + break; + + case Horde_Log::INFO: + case Horde_Log::DEBUG: + $type_message = $this->_cli->blue($flag); + break; + + default: + $type_message = $flag; + } + + return $type_message . $event['message']; + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Simple.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Simple.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Simple.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Simple.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,77 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Formatters + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Formatters + */ +class Horde_Log_Formatter_Simple implements Horde_Log_Formatter +{ + /** + * Format string. + * + * @var string + */ + protected $_format; + + /** + * Constructor. + * + * @param array $options Configuration options: + *
+     * 'format' - (string) The log template.
+     * 
+ * + * @throws InvalidArgumentException + */ + public function __construct($options = null) + { + $format = (is_array($options) && isset($options['format'])) + ? $options['format'] + : $options; + + if (is_null($format)) { + $format = '%timestamp% %levelName%: %message%' . PHP_EOL; + } + + if (!is_string($format)) { + throw new InvalidArgumentException('Format must be a string'); + } + + $this->_format = $format; + } + + /** + * Formats an event to be written by the handler. + * + * @param array $event Log event. + * + * @return string Formatted line. + */ + public function format($event) + { + $output = $this->_format; + foreach ($event as $name => $value) { + $output = str_replace("%$name%", $value, $output); + } + return $output; + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Xml.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Xml.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Xml.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Formatter/Xml.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,69 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Formatters + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Formatters + */ +class Horde_Log_Formatter_Xml implements Horde_Log_Formatter +{ + /** + * Config options. + * + * @var array + */ + protected $_options = array( + 'elementEntry' => 'log', + 'elementTimestamp' => 'timestamp', + 'elementMessage' => 'message', + 'elementLevel' => 'level', + 'lineEnding' => PHP_EOL + ); + + /** + * Constructor. + * + * TODO + */ + public function __construct($options = array()) + { + $this->_options = array_merge($this->_options, $options); + } + + /** + * Formats an event to be written by the handler. + * + * @param array $event Log event. + * + * @return string XML string. + */ + public function format($event) + { + $dom = new DOMDocument(); + + $elt = $dom->appendChild(new DOMElement($this->_options['elementEntry'])); + $elt->appendChild(new DOMElement($this->_options['elementTimestamp'], date('c'))); + $elt->appendChild(new DOMElement($this->_options['elementMessage'], $event['message'])); + $elt->appendChild(new DOMElement($this->_options['elementLevel'], $event['level'])); + + return preg_replace('/<\?xml version="1.0"( encoding="[^\"]*")?\?>\n/u', '', $dom->saveXML()) . $this->_options['lineEnding']; + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Formatter.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Formatter.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Formatter.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Formatter.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,34 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + */ +interface Horde_Log_Formatter +{ + /** + * Formats an event to be written by the handler. + * + * @param array $event Log event. + * + * @return string Formatted line. + */ + public function format($event); + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Base.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Base.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Base.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Base.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,99 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ +abstract class Horde_Log_Handler_Base +{ + /** + * Options. + * + * @var array + */ + protected $_options = array( + 'ident' => '' + ); + + /** + * List of filter objects. + * + * @var array + */ + protected $_filters = array(); + + /** + * Add a filter specific to this handler. + * + * @param Horde_Log_Filter $filter Filter to add. + */ + public function addFilter($filter) + { + $this->_filters[] = is_integer($filter) + ? new Horde_Log_Filter_Level($filter) + : $filter; + } + + /** + * Log a message to this handler. + * + * @param array $event Log event. + */ + public function log($event) + { + // If any local filter rejects the message, don't log it. + foreach ($this->_filters as $filter) { + if (!$filter->accept($event)) { + return; + } + } + + $this->write($event); + } + + /** + * Sets an option specific to the implementation of the log handler. + * + * @param string $optionKey Key name for the option to be changed. Keys + * are handler-specific. + * @param mixed $optionValue New value to assign to the option + * + * @return boolean True. + * @throws Horde_Log_Exception + */ + public function setOption($optionKey, $optionValue) + { + if (!isset($this->_options[$optionKey])) { + throw new Horde_Log_Exception('Unknown option "' . $optionKey . '".'); + } + $this->_options[$optionKey] = $optionValue; + + return true; + } + + /** + * Buffer a message to be stored in the storage. + * + * @param array $event Log event. + */ + abstract public function write($event); + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Cli.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Cli.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Cli.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Cli.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,56 @@ + + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ + +/** + * Logs to the command line interface using Horde_Cli. + * + * @author Jan Schneider + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ +class Horde_Log_Handler_Cli extends Horde_Log_Handler_Stream +{ + /** + * A CLI handler. + * + * @var Horde_Cli + */ + protected $_cli; + + /** + * Class Constructor + * + * @param Horde_Log_Formatter $formatter Log formatter. + */ + public function __construct(Horde_Log_Formatter $formatter = null) + { + $this->_cli = new Horde_Cli(); + $this->_formatter = is_null($formatter) + ? new Horde_Log_Formatter_Cli($this->_cli) + : $formatter; + } + + /** + * Write a message to the log. + * + * @param array $event Log event. + * + * @return boolean True. + * @throws Horde_Log_Exception + */ + public function write($event) + { + $this->_cli->writeln($this->_formatter->format($event)); + return true; + } +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Firebug.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Firebug.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Firebug.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Firebug.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,139 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ +class Horde_Log_Handler_Firebug extends Horde_Log_Handler_Base +{ + /** + * Formats the log message before writing. + * + * @var Horde_Log_Formatter + */ + protected $_formatter; + + /** + * Options to be set by setOption(). + * + * @var array + */ + protected $_options = array( + 'buffering' => false, + 'ident' => '' + ); + + /** + * Array of buffered output. + * + * @var string + */ + protected $_buffer = array(); + + /** + * Mapping of log priorities to Firebug methods. + * + * @var array + */ + protected static $_methods = array( + Horde_Log::EMERG => 'error', + Horde_Log::ALERT => 'error', + Horde_Log::CRIT => 'error', + Horde_Log::ERR => 'error', + Horde_Log::WARN => 'warn', + Horde_Log::NOTICE => 'info', + Horde_Log::INFO => 'info', + Horde_Log::DEBUG => 'debug', + ); + + /** + * Class Constructor + * + * @param Horde_Log_Formatter $formatter Log formatter. + */ + public function __construct(Horde_Log_Formatter $formatter = null) + { + $this->_formatter = is_null($formatter) + ? new Horde_Log_Formatter_Simple() + : $formatter; + } + + /** + * Write a message to the firebug console. This function really just + * writes the message to the buffer. If buffering is enabled, the + * message won't be output until the buffer is flushed. If + * buffering is not enabled, the buffer will be flushed + * immediately. + * + * @param array $event Log event. + * + * @return boolean True. + */ + public function write($event) + { + if (!empty($this->_options['ident'])) { + $event['message'] = $this->_options['ident'] . ' ' . $event['message']; + } + + $this->_buffer[] = $event; + + if (empty($this->_options['buffering'])) { + $this->flush(); + } + + return true; + } + + /** + * Flush the buffer. + */ + public function flush() + { + if (!count($this->_buffer)) { + return true; + } + + $output = array(); + foreach ($this->_buffer as $event) { + $line = trim($this->_formatter->format($event)); + + // Normalize line breaks. + $line = str_replace("\r\n", "\n", $line); + + // Escape line breaks + $line = str_replace("\n", "\\n\\\n", $line); + + // Escape quotes. + $line = str_replace('"', '\\"', $line); + + // Firebug call. + $method = isset(self::$_methods[$event['level']]) + ? self::$_methods[$event['level']] + : 'log'; + $output[] = 'console.' . $method . '("' . $line . '");'; + } + + echo '\n"; + + $this->_buffer = array(); + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Mock.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Mock.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Mock.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Mock.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,59 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ +class Horde_Log_Handler_Mock extends Horde_Log_Handler_Base +{ + /** + * Log events. + * + * @var array + */ + public $events = array(); + + /** + * Was shutdown called? + * + * @var boolean + */ + public $shutdown = false; + + /** + * Write a message to the log. + * + * @param array $event Event data. + */ + public function write($event) + { + $this->events[] = $event; + } + + /** + * Record shutdown + */ + public function shutdown() + { + $this->shutdown = true; + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Null.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Null.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Null.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Null.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,37 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ +class Horde_Log_Handler_Null extends Horde_Log_Handler_Base +{ + /** + * Write a message to the log buffer. + * + * @return boolean True. + */ + public function write($event) + { + return true; + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Scribe.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Scribe.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Scribe.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Scribe.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,90 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ +class Horde_Log_Handler_Scribe extends Horde_Log_Handler_Base +{ + /** + * Scribe client. + * + * @var Horde_Scribe_Client + */ + protected $_scribe; + + /** + * Formats the log message before writing. + * + * @var Horde_Log_Formatter + */ + protected $_formatter; + + /** + * Options to be set by setOption(). + * + * @var array + */ + protected $_options = array( + 'addNewline' => false, + 'category' => 'default', + 'ident' => '' + ); + + /** + * Constructor. + * + * @param Horde_Scribe_Client $scribe Scribe client. + * @param Horde_Log_Formatter $formatter Log formatter. + */ + public function __construct(Horde_Scribe_Client $scribe, + Horde_Log_Formatter $formatter = null) + { + $this->_formatter = is_null($formatter) + ? new Horde_Log_Formatter_Simple() + : $formatter; + $this->_scribe = $scribe; + } + + /** + * Write a message to the log. + * + * @param array $event Log event. + * + * @return boolean True. + */ + public function write($event) + { + if (!empty($this->_options['ident'])) { + $event['message'] = $this->_options['ident'] . ' ' . $event['message']; + } + + $category = isset($event['category']) + ? $event['category'] + : $this->_options['category']; + + $message = $this->_formatter->format($event); + if (!$this->_options['addNewline']) { + $message = rtrim($message); + } + + $this->_scribe->log($category, $message); + + return true; + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Stream.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Stream.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Stream.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Stream.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,124 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ +class Horde_Log_Handler_Stream extends Horde_Log_Handler_Base +{ + /** + * Formats the log message before writing. + * + * @var Horde_Log_Formatter + */ + protected $_formatter; + + /** + * Holds the PHP stream to log to. + * + * @var null|stream + */ + protected $_stream = null; + + /** + * The open mode. + * + * @var string + */ + protected $_mode; + + /** + * The stream to open. + * + * @var string + */ + protected $_streamOrUrl; + + /** + * Class Constructor + * + * @param mixed $streamOrUrl Stream or URL to open as a + * stream. + * @param string $mode Mode, only applicable if a URL + * is given. + * @param Horde_Log_Formatter $formatter Log formatter. + * + * @throws Horde_Log_Exception + */ + public function __construct($streamOrUrl, $mode = 'a+', + Horde_Log_Formatter $formatter = null) + { + $this->_formatter = is_null($formatter) + ? new Horde_Log_Formatter_Simple() + : $formatter; + $this->_mode = $mode; + $this->_streamOrUrl = $streamOrUrl; + + if (is_resource($streamOrUrl)) { + if (get_resource_type($streamOrUrl) != 'stream') { + throw new Horde_Log_Exception(__CLASS__ . ': Resource is not a stream'); + } + + if ($mode && $mode != 'a+') { + throw new Horde_Log_Exception(__CLASS__ . ': Mode cannot be changed on existing streams'); + } + + $this->_stream = $streamOrUrl; + } else { + $this->__wakeup(); + } + } + + /** + * Wakup function - reattaches stream. + * + * @throws Horde_Log_Exception + */ + public function __wakeup() + { + if (!($this->_stream = @fopen($this->_streamOrUrl, $this->_mode, false))) { + throw new Horde_Log_Exception(__CLASS__ . ': "' . $this->_streamOrUrl . '" cannot be opened with mode "' . $this->_mode . '"'); + } + } + + /** + * Write a message to the log. + * + * @param array $event Log event. + * + * @return boolean True. + * @throws Horde_Log_Exception + */ + public function write($event) + { + if (!empty($this->_options['ident'])) { + $event['message'] = $this->_options['ident'] . ' ' . $event['message']; + } + $line = $this->_formatter->format($event); + + if (!@fwrite($this->_stream, $line)) { + throw new Horde_Log_Exception(__CLASS__ . ': Unable to write to stream'); + } + + return true; + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Syslog.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Syslog.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Handler/Syslog.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Handler/Syslog.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,121 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage Handlers + */ +class Horde_Log_Handler_Syslog extends Horde_Log_Handler_Base +{ + /** + * Options to be set by setOption(). + * Sets openlog and syslog options. + * + * @var array + */ + protected $_options = array( + 'defaultPriority' => LOG_ERR, + 'facility' => LOG_USER, + 'ident' => false, + 'openlogOptions' => false + ); + + /** + * Last ident set by a syslog-handler instance. + * + * @var string + */ + protected $_lastIdent; + + /** + * Last facility name set by a syslog-handler instance. + * + * @var string + */ + protected $_lastFacility; + + /** + * Map of log levels to syslog priorities. + * + * @var array + */ + protected $_priorities = array( + Horde_Log::EMERG => LOG_EMERG, + Horde_Log::ALERT => LOG_ALERT, + Horde_Log::CRIT => LOG_CRIT, + Horde_Log::ERR => LOG_ERR, + Horde_Log::WARN => LOG_WARNING, + Horde_Log::NOTICE => LOG_NOTICE, + Horde_Log::INFO => LOG_INFO, + Horde_Log::DEBUG => LOG_DEBUG, + ); + + /** + * Write a message to the log. + * + * @param array $event Log event. + * + * @return boolean True. + * @throws Horde_Log_Exception + */ + public function write($event) + { + if (($this->_options['ident'] !== $this->_lastIdent) || + ($this->_options['facility'] !== $this->_lastFacility)) { + $this->_initializeSyslog(); + } + + $priority = $this->_toSyslog($event['level']); + if (!syslog($priority, $event['message'])) { + throw new Horde_Log_Exception('Unable to log message'); + } + + return true; + } + + /** + * Translate a log level to a syslog LOG_* priority. + * + * @param integer $level Log level. + * + * @return integer A LOG_* constant. + */ + protected function _toSyslog($level) + { + return isset($this->_priorities[$level]) + ? $this->_priorities[$level] + : $this->_options['defaultPriority']; + } + + /** + * Initialize syslog / set ident and facility. + * + * @param string $ident Ident. + * @param string $facility Syslog facility. + * + * @throws Horde_Log_Exception + */ + protected function _initializeSyslog() + { + $this->_lastIdent = $this->_options['ident']; + $this->_lastFacility = $this->_options['facility']; + + if (!openlog($this->_options['ident'], $this->_options['openlogOptions'], $this->_options['facility'])) { + throw new Horde_Log_Exception('Unable to open syslog'); + } + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Logger.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Logger.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log/Logger.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log/Logger.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,253 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * + * @method void LOGLEVEL() LOGLEVEL($event) Log an event at LOGLEVEL, where LOGLEVEL has been added with addLevel() or already exists + * @method void emerg() emerg($event) Log an event at the EMERG log level + * @method void alert() alert($event) Log an event at the ALERT log level + * @method void crit() crit($event) Log an event at the CRIT log level + * @method void err() err($event) Log an event at the ERR log level + * @method void warn() warn($event) Log an event at the WARN log level + * @method void notice() notice($event) Log an event at the NOTICE log level + * @method void info() info($event) Log an event at the INFO log level + * @method void debug() debug($event) Log an event at the DEBUG log level + */ +class Horde_Log_Logger implements Serializable +{ + /* Serialize version. */ + const VERSION = 1; + + /** + * Log levels where the keys are the level priorities and the values are + * the level names. + * + * @var array + */ + private $_levels = array(); + + /** + * Horde_Log_Handler_Base objects. + * + * @var array + */ + private $_handlers = array(); + + /** + * Horde_Log_Filter objects. + * + * @var array + */ + private $_filters = array(); + + /** + * Constructor. + * + * @param Horde_Log_Handler_Base|null $handler Default handler. + */ + public function __construct($handler = null) + { + if (!is_null($handler)) { + $this->addHandler($handler); + } + + $this->_init(); + } + + /** + * Serialize. + * + * @return string Serialized representation of this object. + */ + public function serialize() + { + return serialize(array( + self::VERSION, + $this->_filters, + $this->_handlers + )); + } + + /** + * Unserialize. + * + * @param string $data Serialized data. + * + * @throws Exception + */ + public function unserialize($data) + { + $data = @unserialize($data); + if (!is_array($data) || + !isset($data[0]) || + ($data[0] != self::VERSION)) { + throw new Exception('Cache version change'); + } + + $this->_filters = $data[1]; + $this->_handlers = $data[2]; + + $this->_init(); + } + + /** + * Initialization tasks. + */ + protected function _init() + { + $r = new ReflectionClass('Horde_Log'); + $this->_levels = array_flip($r->getConstants()); + } + + /** + * Undefined method handler allows a shortcut: + *
+     * $log->levelName('message');
+     *   instead of
+     * $log->log('message', Horde_Log_LEVELNAME);
+     * 
+ * + * @param string $method Log level name. + * @param string $params Message to log. + */ + public function __call($method, $params) + { + $levelName = strtoupper($method); + if (($level = array_search($levelName, $this->_levels)) !== false) { + $this->log(array_shift($params), $level); + } else { + throw new Horde_Log_Exception('Bad log level ' . $levelName); + } + } + + /** + * Log a message at a level + * + * @param mixed $event Message to log, either an array or a string. + * @param integer $level Log level of message, required if $message is a + * string. + */ + public function log($event, $level = null) + { + if (empty($this->_handlers)) { + throw new Horde_Log_Exception('No handlers were added'); + } + + // Create an event array from the given arguments. + if (is_array($event)) { + // If we are passed an array, it must contain 'message' + // and 'level' indices. + if (!isset($event['message'])) { + throw new Horde_Log_Exception('Event array did not contain a message'); + } + if (!isset($event['level'])) { + if (is_null($level)) { + throw new Horde_Log_Exception('Event array did not contain a log level'); + } + $event['level'] = $level; + } + } else { + // Create an event array from the message and level + // arguments. + $event = array('message' => $event, 'level' => $level); + } + + if (!isset($this->_levels[$event['level']]) || + !is_string($this->_levels[$event['level']])) { + throw new Horde_Log_Exception('Bad log level: ' . $event['level']); + } + + // Fill in the level name and timestamp for filters, formatters, + // handlers. + $event['levelName'] = $this->_levels[$event['level']]; + + if (!isset($event['timestamp'])) { + $event['timestamp'] = date('c'); + } + + // If any global filter rejects the event, don't log it. + foreach ($this->_filters as $filter) { + if (!$filter->accept($event)) { + return; + } + } + + foreach ($this->_handlers as $handler) { + $handler->log($event); + } + } + + /** + * Does this logger have the level $name already? + * + * @param string $name The level name to check for. + * + * @return boolean Whether the logger already has the specific level + * name. + */ + public function hasLevel($name) + { + return (boolean)array_search($name, $this->_levels); + } + + /** + * Add a custom log level + * + * @param string $name Name of level. + * @param integer $level Numeric level. + */ + public function addLevel($name, $level) + { + // Log level names must be uppercase for predictability. + $name = strtoupper($name); + + if (isset($this->_levels[$level]) || $this->hasLevel($name)) { + throw new Horde_Log_Exception('Existing log levels cannot be overwritten'); + } + + $this->_levels[$level] = $name; + } + + /** + * Add a filter that will be applied before all log handlers. + * Before a message will be received by any of the handlers, it + * must be accepted by all filters added with this method. + * + * @param Horde_Log_Filter $filter Filter to add. + */ + public function addFilter($filter) + { + $this->_filters[] = is_integer($filter) + ? new Horde_Log_Filter_Level($filter) + : $filter; + } + + /** + * Add a handler. A handler is responsible for taking a log + * message and writing it out to storage. + * + * @param Horde_Log_Handler_Base $handler Handler to add. + */ + public function addHandler($handler) + { + $this->_handlers[] = $handler; + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log.php php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/lib/Horde/Log.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/lib/Horde/Log.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,46 @@ + + * @author Chuck Hagenbuch + * @license http://www.horde.org/licenses/bsd BSD + */ + +/** + * @category Horde + * @package Log + */ +class Horde_Log { + + /** Emergency: system is unusable */ + const EMERG = 0; + + /** Alert: action must be taken immediately */ + const ALERT = 1; + + /** Critical: critical conditions */ + const CRIT = 2; + + /** Error: error conditions */ + const ERR = 3; + + /** Warning: warning conditions */ + const WARN = 4; + + /** Notice: normal but significant condition */ + const NOTICE = 5; + + /** Informational: informational messages */ + const INFO = 6; + + /** Debug: debug-level messages */ + const DEBUG = 7; + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/AllTests.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/AllTests.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/AllTests.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/AllTests.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,3 @@ +run(); diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/ChainingTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/ChainingTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/ChainingTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/ChainingTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,79 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_Filter_ChainingTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + date_default_timezone_set('America/New_York'); + + $this->log = fopen('php://memory', 'w'); + $this->logger = new Horde_Log_Logger(); + $this->logger->addHandler(new Horde_Log_Handler_Stream($this->log)); + } + + public function tearDown() + { + fclose($this->log); + } + + public function testFilterAllHandlers() + { + // filter out anything above a WARNing for all handlers + $this->logger->addFilter(Horde_Log::WARN); + + $this->logger->info($ignored = 'info-message-ignored'); + $this->logger->warn($logged = 'warn-message-logged'); + + rewind($this->log); + $logdata = stream_get_contents($this->log); + + $this->assertNotContains($ignored, $logdata); + $this->assertContains($logged, $logdata); + } + + + public function testFilterOnSpecificHandler() + { + $log2 = fopen('php://memory', 'w'); + $handler2 = new Horde_Log_Handler_Stream($log2); + $handler2->addFilter(Horde_Log::ERR); + + $this->logger->addHandler($handler2); + + $this->logger->warn($warn = 'warn-message'); + $this->logger->err($err = 'err-message'); + + rewind($this->log); + $logdata = stream_get_contents($this->log); + $this->assertContains($warn, $logdata); + $this->assertContains($err, $logdata); + + rewind($log2); + $logdata = stream_get_contents($log2); + $this->assertContains($err, $logdata); + $this->assertNotContains($warn, $logdata); + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/ConstraintTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/ConstraintTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/ConstraintTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/ConstraintTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,111 @@ + + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author James Pepin + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_Filter_ConstraintTest extends Horde_Test_Case +{ + public function testFilterDoesNotAcceptWhenRequiredFieldIsMissing() + { + $event = array( + 'someotherfield' => 'other value', + ); + $filterator = new Horde_Log_Filter_Constraint(); + $filterator->addRequiredField('required_field'); + + $this->assertFalse($filterator->accept($event)); + } + + public function testFilterAcceptsWhenRequiredFieldisPresent() + { + $event = array( + 'required_field' => 'somevalue', + 'someotherfield' => 'other value', + ); + $filterator = new Horde_Log_Filter_Constraint(); + $filterator->addRequiredField('required_field'); + + $this->assertTrue($filterator->accept($event)); + } + + public function testFilterAcceptsWhenRegexMatchesField() + { + $event = array( + 'regex_field' => 'somevalue', + 'someotherfield' => 'other value', + ); + $filterator = new Horde_Log_Filter_Constraint(); + $filterator->addRegex('regex_field', '/somevalue/'); + + $this->assertTrue($filterator->accept($event)); + } + + public function testFilterAcceptsWhenRegex_DOESNOT_MatcheField() + { + $event = array( + 'regex_field' => 'somevalue', + 'someotherfield' => 'other value', + ); + $filterator = new Horde_Log_Filter_Constraint(); + $filterator->addRegex('regex_field', '/someothervalue/'); + + $this->assertFalse($filterator->accept($event)); + } + + private function getConstraintMock($returnVal) + { + $const = $this->getMock('Horde_Constraint', array('evaluate')); + $const->expects($this->once()) + ->method('evaluate') + ->will($this->returnValue($returnVal)); + return $const; + } + + public function testFilterCallsEvalOnAllConstraintsWhenTheyAreAllTrue() + { + $filterator = new Horde_Log_Filter_Constraint(); + $filterator->addConstraint('fieldname', $this->getConstraintMock(true)); + $filterator->addConstraint('fieldname', $this->getConstraintMock(true)); + + $filterator->accept(array('fieldname' => 'foo')); + } + + public function testFilterStopsWhenItFindsAFalseCondition() + { + $filterator = new Horde_Log_Filter_Constraint(); + $filterator->addConstraint('fieldname', $this->getConstraintMock(true)); + $filterator->addConstraint('fieldname', $this->getConstraintMock(true)); + $filterator->addConstraint('fieldname', new Horde_Constraint_AlwaysFalse()); + + $const = $this->getMock('Horde_Constraint', array('evaluate')); + $const->expects($this->never()) + ->method('evaluate'); + $filterator->addConstraint('fieldname', $const); + $filterator->accept(array('fieldname' => 'foo')); + + } + + public function testFilterAcceptCallsConstraintOnNullWhenFieldDoesnotExist() + { + $filterator = new Horde_Log_Filter_Constraint(); + $const = $this->getMock('Horde_Constraint', array('evaluate')); + $const->expects($this->once()) + ->method('evaluate') + ->with(null); + $filterator->addConstraint('fieldname', $const); + $filterator->accept(array('someotherfield' => 'foo')); + } +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/ExactLevelTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/ExactLevelTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/ExactLevelTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/ExactLevelTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,54 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_Filter_ExactLevelTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + // accept at and only at level 2 + $this->filter = new Horde_Log_Filter_ExactLevel(2); + } + + public function testLevelFilterAccept() + { + $this->assertTrue($this->filter->accept(array('message' => '', 'level' => 2))); + } + + public function testLevelFilterReject() + { + $this->assertFalse($this->filter->accept(array('message' => '', 'level' => 1))); + $this->assertFalse($this->filter->accept(array('message' => '', 'level' => 3))); + } + + public function testConstructorThrowsOnInvalidLevel() + { + try { + new Horde_Log_Filter_Level('foo'); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('InvalidArgumentException', $e); + $this->assertRegExp('/must be an integer/i', $e->getMessage()); + } + } +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/LevelTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/LevelTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/LevelTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/LevelTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,54 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_Filter_LevelTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + // accept at or below level 2 + $this->filter = new Horde_Log_Filter_Level(2); + } + + public function testLevelFilterAccept() + { + $this->assertTrue($this->filter->accept(array('message' => '', 'level' => 2))); + $this->assertTrue($this->filter->accept(array('message' => '', 'level' => 1))); + } + + public function testLevelFilterReject() + { + $this->assertFalse($this->filter->accept(array('message' => '', 'level' => 3))); + } + + public function testConstructorThrowsOnInvalidLevel() + { + try { + new Horde_Log_Filter_Level('foo'); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('InvalidArgumentException', $e); + $this->assertRegExp('/must be an integer/i', $e->getMessage()); + } + } +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/MessageTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/MessageTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/MessageTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/MessageTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,45 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_Filter_MessageTest extends PHPUnit_Framework_TestCase +{ + + public function testMessageFilterRecognizesInvalidRegularExpression() + { + try { + $filter = new Horde_Log_Filter_Message('invalid regexp'); + $this->fail(); + } catch (InvalidArgumentException $e) { + $this->assertRegexp('/invalid reg/i', $e->getMessage()); + } + } + + public function testMessageFilter() + { + $filter = new Horde_Log_Filter_Message('/accept/'); + $this->assertTrue($filter->accept(array('message' => 'foo accept bar', 'level' => 0))); + $this->assertFalse($filter->accept(array('message' => 'foo reject bar', 'level' => 0))); + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/SuppressTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/SuppressTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Filter/SuppressTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Filter/SuppressTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,60 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_Filter_SuppressTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + $this->filter = new Horde_Log_Filter_Suppress(); + } + + public function testSuppressIsInitiallyOff() + { + $this->assertTrue($this->filter->accept(array())); + } + + public function testSuppressOn() + { + $this->filter->suppress(true); + $this->assertFalse($this->filter->accept(array())); + $this->assertFalse($this->filter->accept(array())); + } + + public function testSuppressOff() + { + $this->filter->suppress(false); + $this->assertTrue($this->filter->accept(array())); + $this->assertTrue($this->filter->accept(array())); + } + + public function testSuppressCanBeReset() + { + $this->filter->suppress(true); + $this->assertFalse($this->filter->accept(array())); + $this->filter->suppress(false); + $this->assertTrue($this->filter->accept(array())); + $this->filter->suppress(true); + $this->assertFalse($this->filter->accept(array())); + } +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Formatter/SimpleTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Formatter/SimpleTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Formatter/SimpleTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Formatter/SimpleTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,48 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_Formatter_SimpleTest extends PHPUnit_Framework_TestCase +{ + public function testConstructorThrowsOnBadFormatString() + { + try { + new Horde_Log_Formatter_Simple(1); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('InvalidArgumentException', $e); + $this->assertRegExp('/must be a string/i', $e->getMessage()); + } + } + + public function testDefaultFormat() + { + $f = new Horde_Log_Formatter_Simple(); + $line = $f->format(array('message' => $message = 'message', + 'level' => $level = Horde_Log::ALERT, + 'levelName' => $levelName = 'ALERT')); + + $this->assertContains($message, $line); + $this->assertContains($levelName, $line); + } +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Formatter/XmlTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Formatter/XmlTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Formatter/XmlTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Formatter/XmlTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,55 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + */ +class Horde_Log_Formatter_XmlTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + date_default_timezone_set('America/New_York'); + } + + public function testDefaultFormat() + { + $f = new Horde_Log_Formatter_Xml(); + $line = $f->format(array('message' => $message = 'message', 'level' => $level = 1)); + + $this->assertContains($message, $line); + $this->assertContains((string)$level, $line); + } + + public function testXmlDeclarationIsStripped() + { + $f = new Horde_Log_Formatter_Xml(); + $line = $f->format(array('message' => $message = 'message', 'level' => $level = 1)); + + $this->assertNotContains('<\?xml version=', $line); + } + + public function testXmlValidates() + { + $f = new Horde_Log_Formatter_Xml(); + $line = $f->format(array('message' => $message = 'message', 'level' => $level = 1)); + + $sxml = @simplexml_load_string($line); + $this->assertInstanceOf('SimpleXMLElement', $sxml, 'Formatted XML is invalid'); + } +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Handler/FirebugTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Handler/FirebugTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Handler/FirebugTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Handler/FirebugTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,61 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_Handler_FirebugTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + date_default_timezone_set('America/New_York'); + } + + public function testSettingBadOptionThrows() + { + try { + $handler = new Horde_Log_Handler_Stream('php://memory'); + $handler->setOption('foo', 42); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('Horde_Log_Exception', $e); + $this->assertRegExp('/unknown option/i', $e->getMessage()); + } + } + + public function testWrite() + { + ob_start(); + + $handler = new Horde_Log_Handler_Firebug(); + $handler->write(array('message' => $message = 'message-to-log', + 'level' => $level = Horde_Log::ALERT, + 'levelName' => $levelName = 'ALERT', + 'timestamp' => date('c'))); + + $contents = ob_get_clean(); + + $date = '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}-\d{2}:\d{2}'; + + $this->assertRegExp("/console.error\(\"$date $levelName: $message\"\);/", $contents); + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Handler/NullTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Handler/NullTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Handler/NullTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Handler/NullTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,32 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_Handler_NullTest extends PHPUnit_Framework_TestCase +{ + public function testWrite() + { + $handler = new Horde_Log_Handler_Null(); + $this->assertTrue($handler->write(array('message' => 'foo', 'level' => 42))); + } +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Handler/StreamTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Handler/StreamTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/Handler/StreamTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/Handler/StreamTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,125 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_Handler_StreamTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + date_default_timezone_set('America/New_York'); + } + + public function testConstructorThrowsWhenResourceIsNotStream() + { + $resource = xml_parser_create(); + try { + new Horde_Log_Handler_Stream($resource); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('Horde_Log_Exception', $e); + $this->assertRegExp('/not a stream/i', $e->getMessage()); + } + xml_parser_free($resource); + } + + public function testConstructorWithValidStream() + { + $stream = fopen('php://memory', 'a'); + new Horde_Log_Handler_Stream($stream); + } + + public function testConstructorWithValidUrl() + { + new Horde_Log_Handler_Stream('php://memory'); + } + + public function testConstructorThrowsWhenModeSpecifiedForExistingStream() + { + $stream = fopen('php://memory', 'a'); + try { + new Horde_Log_Handler_Stream($stream, 'w'); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('Horde_Log_Exception', $e); + $this->assertRegExp('/existing stream/i', $e->getMessage()); + } + } + + public function testConstructorThrowsWhenStreamCannotBeOpened() + { + try { + new Horde_Log_Handler_Stream(''); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('Horde_Log_Exception', $e); + $this->assertRegExp('/cannot be opened/i', $e->getMessage()); + } + } + + public function testSettingBadOptionThrows() + { + try { + $handler = new Horde_Log_Handler_Stream('php://memory'); + $handler->setOption('foo', 42); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('Horde_Log_Exception', $e); + $this->assertRegExp('/unknown option/i', $e->getMessage()); + } + } + + public function testWrite() + { + $stream = fopen('php://memory', 'a'); + + $handler = new Horde_Log_Handler_Stream($stream); + $handler->write(array('message' => $message = 'message-to-log', + 'level' => $level = Horde_Log::ALERT, + 'levelName' => $levelName = 'ALERT', + 'timestamp' => date('c'))); + + rewind($stream); + $contents = stream_get_contents($stream); + fclose($stream); + + $date = '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}-\d{2}:\d{2}'; + + $this->assertRegExp("/$date $levelName: $message/", $contents); + } + + public function testWriteThrowsWhenStreamWriteFails() + { + $stream = fopen('php://memory', 'a'); + $handler = new Horde_Log_Handler_Stream($stream); + fclose($stream); + + try { + $handler->write(array('message' => 'foo', 'level' => 1)); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('Horde_Log_Exception', $e); + $this->assertRegExp('/unable to write/i', $e->getMessage()); + } + } + +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/LogTest.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/LogTest.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/LogTest.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/LogTest.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,147 @@ + + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ + +/** + * @author Mike Naberezny + * @author Chuck Hagenbuch + * @category Horde + * @license http://www.horde.org/licenses/bsd BSD + * @package Log + * @subpackage UnitTests + */ +class Horde_Log_LogTest extends PHPUnit_Framework_TestCase +{ + public function setUp() + { + date_default_timezone_set('America/New_York'); + + $this->log = fopen('php://memory', 'a'); + $this->handler = new Horde_Log_Handler_Stream($this->log); + } + + // Handlers + + public function testHandlerCanBeAddedWithConstructor() + { + $logger = new Horde_Log_Logger($this->handler); + $logger->log($message = 'message-to-long', Horde_Log::INFO); + + rewind($this->log); + $this->assertContains($message, stream_get_contents($this->log)); + } + + public function testaddHandler() + { + $logger = new Horde_Log_Logger(); + $logger->addHandler($this->handler); + $logger->log($message = 'message-to-log', Horde_Log::INFO); + + rewind($this->log); + $this->assertContains($message, stream_get_contents($this->log)); + } + + public function testaddHandlerAddsMultipleHandlers() + { + $logger = new Horde_Log_Logger(); + + // create handlers for two separate streams of temporary memory + $log1 = fopen('php://memory', 'a'); + $handler1 = new Horde_Log_Handler_Stream($log1); + $log2 = fopen('php://memory', 'a'); + $handler2 = new Horde_Log_Handler_Stream($log2); + + // add the handlers + $logger->addHandler($handler1); + $logger->addHandler($handler2); + + // log to both handlers + $logger->log($message = 'message-sent-to-both-logs', Horde_Log::INFO); + + // verify both handlers were called by the logger + rewind($log1); + $this->assertContains($message, stream_get_contents($log1)); + rewind($log2); + $this->assertContains($message, stream_get_contents($log2)); + + // prove the two memory streams are different + // and both handlers were indeed called + fwrite($log1, 'foo'); + $this->assertNotEquals(ftell($log1), ftell($log2)); + } + + public function testLoggerThrowsWhenNoHandlers() + { + $logger = new Horde_Log_Logger(); + try { + $logger->log('message', Horde_Log::INFO); + $this->fail(); + } catch (Horde_Log_Exception $e) { + $this->assertRegexp('/no handler/i', $e->getMessage()); + } + } + + // Levels + + public function testLogThrowsOnBadLogLevel() + { + $logger = new Horde_Log_Logger($this->handler); + try { + $logger->log('foo', 42); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('Horde_Log_Exception', $e); + $this->assertRegExp('/bad log level/i', $e->getMessage()); + } + } + + public function testLogThrough__callThrowsOnBadLogLevel() + { + $logger = new Horde_Log_Logger($this->handler); + try { + $logger->nonexistantLevel(''); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('Horde_Log_Exception', $e); + $this->assertRegExp('/bad log level/i', $e->getMessage()); + } + } + + public function testAddingLevelThrowsWhenOverridingBuiltinLogLevel() + { + try { + $logger = new Horde_Log_Logger($this->handler); + $logger->addLevel('BOB', 0); + $this->fail(); + } catch (Exception $e) { + $this->assertInstanceOf('Horde_Log_Exception', $e); + $this->assertRegExp('/existing log level/i', $e->getMessage()); + } + + } + + public function testAddLogLevel() + { + $logger = new Horde_Log_Logger($this->handler); + $logger->addLevel($levelName = 'EIGHT', $level = 8); + + $logger->eight($message = 'eight message'); + + rewind($this->log); + $logdata = stream_get_contents($this->log); + $this->assertContains($levelName, $logdata); + $this->assertContains($message, $logdata); + } +} diff -Nru php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/bootstrap.php php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/bootstrap.php --- php-horde-log-2.0.1/Horde_Log-2.1.0/test/Horde/Log/bootstrap.php 1970-01-01 00:00:00.000000000 +0000 +++ php-horde-log-2.1.0/Horde_Log-2.1.0/test/Horde/Log/bootstrap.php 2013-10-15 10:19:25.000000000 +0000 @@ -0,0 +1,3 @@ + diff -Nru php-horde-log-2.0.1/debian/changelog php-horde-log-2.1.0/debian/changelog --- php-horde-log-2.0.1/debian/changelog 2013-06-06 06:21:02.000000000 +0000 +++ php-horde-log-2.1.0/debian/changelog 2013-10-22 15:51:11.000000000 +0000 @@ -1,3 +1,9 @@ +php-horde-log (2.1.0-1) unstable; urgency=low + + * New upstream version 2.1.0 + + -- Mathieu Parent Tue, 22 Oct 2013 17:51:09 +0200 + php-horde-log (2.0.1-3) unstable; urgency=low * Use pristine-tar diff -Nru php-horde-log-2.0.1/package.xml php-horde-log-2.1.0/package.xml --- php-horde-log-2.0.1/package.xml 2012-11-30 18:01:33.000000000 +0000 +++ php-horde-log-2.1.0/package.xml 2013-10-15 10:19:25.000000000 +0000 @@ -17,11 +17,11 @@ mike@maintainable.com yes - 2012-11-19 - + 2013-10-15 + - 2.0.1 - 1.1.0 + 2.1.0 + 1.2.0 stable @@ -29,19 +29,21 @@ BSD-2-Clause -* [mms] Use new Horde_Test layout. +* [jan] Add a CLI formatter and handler. - + + + @@ -95,6 +97,13 @@ + Horde_Cli + pear.horde.org + 2.0.0 + 3.0.0alpha1 + 3.0.0alpha1 + + Horde_Scribe pear.horde.org 2.0.0 @@ -126,9 +135,11 @@ + + @@ -334,5 +345,20 @@ * [mms] Use new Horde_Test layout. + + + 2.1.0 + 1.2.0 + + + stable + stable + + 2013-10-15 + BSD-2-Clause + +* [jan] Add a CLI formatter and handler. + +