package.xml0000664000175000017500000004000412653742146011307 0ustar janjan Horde_Log pear.horde.org Log Horde Logging library Horde Logging package with configurable handlers, filters, and formatting. Chuck Hagenbuch chuck chuck@horde.org yes Mike Naberezny mnaberez mike@maintainable.com yes 2016-02-01 2.1.3 1.2.0 stable stable BSD-2-Clause * [jan] Mark PHP 7 as supported. 5.3.0 8.0.0alpha1 8.0.0alpha1 1.7.0 Horde_Constraint pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Exception pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Util pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Cli pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Scribe pear.horde.org 2.0.0 3.0.0alpha1 3.0.0alpha1 Horde_Test pear.horde.org 2.1.0 3.0.0alpha1 3.0.0alpha1 dom 1.0.0alpha1 1.0.0 alpha alpha 2011-03-08 BSD-2-Clause * First alpha release for Horde 4. * Added Horde_Log_Filter_Constraint, for flexible filtering per-field by the Horde_Constraint package. 1.0.0beta1 1.0.0 beta beta 2011-03-16 BSD-2-Clause * First beta release for Horde 4. 1.0.0RC1 1.0.0 beta beta 2011-03-22 BSD-2-Clause * First release candidate for Horde 4. 1.0.0RC2 1.0.0 beta beta 2011-03-29 BSD-2-Clause * Second release candidate for Horde 4. 1.0.0 1.0.0 stable stable 2011-04-06 BSD-2-Clause * First stable release for Horde 4. 1.1.0 1.1.0 stable stable 2011-07-27 BSD-2-Clause * [cjh] New log filter for exact level matching (Bryan Alves <bryanalves@gmail.com>) 1.1.1 1.1.0 stable stable 2011-08-17 BSD-2-Clause * [jan] Add 'ident' option to all handlers (Gonçalo Queirós <goncalo.queiros@portugalmail.net>, Request #9322). 1.1.2 1.1.0 stable stable 2011-10-11 BSD-2-Clause * [gwr] Fix installation paths (Bug #10588) 2.0.0alpha1 1.1.0 alpha stable 2012-07-05 BSD-2-Clause * First alpha release for Horde 5. 2.0.0beta1 1.1.0 beta stable 2012-07-19 BSD-2-Clause * First beta release for Horde 5. 2.0.0 1.1.0 stable stable 2012-10-30 BSD-2-Clause * First stable release for Horde 5. 2.0.1 1.1.0 stable stable 2012-11-19 BSD-2-Clause * [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. 2.1.1 1.2.0 stable stable 2015-01-09 BSD-2-Clause * [jan] Add Composer definition. 2.1.2 1.2.0 stable stable 2015-04-28 BSD-2-Clause * [jan] Fix issues with certain locales like Turkish. 2.1.3 1.2.0 stable stable 2016-02-01 BSD-2-Clause * [jan] Mark PHP 7 as supported. Horde_Log-2.1.3/doc/Horde/Log/COPYING0000664000175000017500000000243012653742146015056 0ustar janjan Copyright 1999-2016 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. Horde_Log-2.1.3/lib/Horde/Log/Filter/Constraint.php0000664000175000017500000001030112653742146020102 0ustar janjan * @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; } } Horde_Log-2.1.3/lib/Horde/Log/Filter/ExactLevel.php0000664000175000017500000000214412653742146020020 0ustar janjan * @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; } } Horde_Log-2.1.3/lib/Horde/Log/Filter/Level.php0000664000175000017500000000300112653742146017024 0ustar janjan * @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); } } Horde_Log-2.1.3/lib/Horde/Log/Filter/Message.php0000664000175000017500000000311712653742146017351 0ustar janjan * @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); } } Horde_Log-2.1.3/lib/Horde/Log/Filter/Suppress.php0000664000175000017500000000253012653742146017607 0ustar janjan * @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; } } Horde_Log-2.1.3/lib/Horde/Log/Formatter/Cli.php0000664000175000017500000000326512653742146017216 0ustar janjan * @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']; } } Horde_Log-2.1.3/lib/Horde/Log/Formatter/Simple.php0000664000175000017500000000354112653742146017735 0ustar janjan * @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; } } Horde_Log-2.1.3/lib/Horde/Log/Formatter/Xml.php0000664000175000017500000000366112653742146017247 0ustar janjan * @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']; } } Horde_Log-2.1.3/lib/Horde/Log/Handler/Base.php0000664000175000017500000000460412653742146016771 0ustar janjan * @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); } Horde_Log-2.1.3/lib/Horde/Log/Handler/Cli.php0000664000175000017500000000240112653742146016617 0ustar janjan * @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; } } Horde_Log-2.1.3/lib/Horde/Log/Handler/Firebug.php0000664000175000017500000000667112653742146017510 0ustar janjan * @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(); } } Horde_Log-2.1.3/lib/Horde/Log/Handler/Mock.php0000664000175000017500000000230512653742146017004 0ustar janjan * @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; } } Horde_Log-2.1.3/lib/Horde/Log/Handler/Null.php0000664000175000017500000000160112653742146017023 0ustar janjan * @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; } } Horde_Log-2.1.3/lib/Horde/Log/Handler/Scribe.php0000664000175000017500000000412312653742146017322 0ustar janjan * @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; } } Horde_Log-2.1.3/lib/Horde/Log/Handler/Stream.php0000664000175000017500000000642412653742146017354 0ustar janjan * @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; } } Horde_Log-2.1.3/lib/Horde/Log/Handler/Syslog.php0000664000175000017500000000606212653742146017377 0ustar janjan * @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'); } } } Horde_Log-2.1.3/lib/Horde/Log/Exception.php0000664000175000017500000000123012653742146016470 0ustar janjan * @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 { } Horde_Log-2.1.3/lib/Horde/Log/Filter.php0000664000175000017500000000212412653742146015762 0ustar janjan * @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); } Horde_Log-2.1.3/lib/Horde/Log/Formatter.php0000664000175000017500000000150312653742146016500 0ustar janjan * @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); } Horde_Log-2.1.3/lib/Horde/Log/Logger.php0000664000175000017500000001615412653742146015764 0ustar janjan * @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 = Horde_String::upper($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 = Horde_String::upper($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; } } Horde_Log-2.1.3/lib/Horde/Log.php0000664000175000017500000000174012653742146014540 0ustar janjan * @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; } Horde_Log-2.1.3/test/Horde/Log/Filter/ChainingTest.php0000664000175000017500000000435312653742146020561 0ustar janjan * @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); } } Horde_Log-2.1.3/test/Horde/Log/Filter/ConstraintTest.php0000664000175000017500000000712112653742146021161 0ustar janjan * @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')); } } Horde_Log-2.1.3/test/Horde/Log/Filter/ExactLevelTest.php0000664000175000017500000000312112653742146021065 0ustar janjan * @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()); } } } Horde_Log-2.1.3/test/Horde/Log/Filter/LevelTest.php0000664000175000017500000000310312653742146020100 0ustar janjan * @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()); } } } Horde_Log-2.1.3/test/Horde/Log/Filter/MessageTest.php0000664000175000017500000000254212653742146020423 0ustar janjan * @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))); } } Horde_Log-2.1.3/test/Horde/Log/Filter/SuppressTest.php0000664000175000017500000000331212653742146020657 0ustar janjan * @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())); } } Horde_Log-2.1.3/test/Horde/Log/Formatter/SimpleTest.php0000664000175000017500000000274112653742146021007 0ustar janjan * @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); } } Horde_Log-2.1.3/test/Horde/Log/Formatter/XmlTest.php0000664000175000017500000000316212653742146020314 0ustar janjan * @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'); } } Horde_Log-2.1.3/test/Horde/Log/Handler/FirebugTest.php0000664000175000017500000000343512653742146020554 0ustar janjan * @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); } } Horde_Log-2.1.3/test/Horde/Log/Handler/NullTest.php0000664000175000017500000000163312653742146020101 0ustar janjan * @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))); } } Horde_Log-2.1.3/test/Horde/Log/Handler/StreamTest.php0000664000175000017500000000741512653742146020426 0ustar janjan * @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()); } } } Horde_Log-2.1.3/test/Horde/Log/AllTests.php0000664000175000017500000000013212653742146016476 0ustar janjanrun(); Horde_Log-2.1.3/test/Horde/Log/bootstrap.php0000664000175000017500000000014312653742146016762 0ustar janjan * @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); } } Horde_Log-2.1.3/test/Horde/Log/phpunit.xml0000664000175000017500000000005612653742146016450 0ustar janjan