From commits-return-103-apmail-logging-commits-archive=logging.apache.org@logging.apache.org Mon Sep 19 06:48:29 2011 Return-Path: X-Original-To: apmail-logging-commits-archive@minotaur.apache.org Delivered-To: apmail-logging-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F0CC79D06 for ; Mon, 19 Sep 2011 06:48:29 +0000 (UTC) Received: (qmail 13793 invoked by uid 500); 19 Sep 2011 06:48:29 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 13762 invoked by uid 500); 19 Sep 2011 06:48:29 -0000 Mailing-List: contact commits-help@logging.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@logging.apache.org Delivered-To: mailing list commits@logging.apache.org Received: (qmail 13736 invoked by uid 99); 19 Sep 2011 06:48:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Sep 2011 06:48:29 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Sep 2011 06:48:19 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D9D58238889B; Mon, 19 Sep 2011 06:47:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1172485 - in /logging/log4php/branches/experimental/config-adapters/src: main/php/ main/php/configurators/ test/php/ test/php/configurators/ test/php/renderers/ Date: Mon, 19 Sep 2011 06:47:54 -0000 To: commits@logging.apache.org From: ihabunek@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20110919064756.D9D58238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ihabunek Date: Mon Sep 19 06:47:53 2011 New Revision: 1172485 URL: http://svn.apache.org/viewvc?rev=1172485&view=rev Log: More work including tests and bugfixes found by tests. Also documentation. Added: logging/log4php/branches/experimental/config-adapters/src/test/php/LoggerConfiguratorTest.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterINITest.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterPHPTest.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.ini logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.xml logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.ini logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.xml logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.ini logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.xml logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.ini logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.xml Removed: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfiguratorBasicTest.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfiguratorIniTest.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfiguratorPhpTest.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfiguratorXmlTest.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/test1.php logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/test1.properties logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/test1.xml logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/test2.properties logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/test3.properties logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/test4.properties logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/test5.properties logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/test6.properties Modified: logging/log4php/branches/experimental/config-adapters/src/main/php/Logger.php logging/log4php/branches/experimental/config-adapters/src/main/php/LoggerAppenderPool.php logging/log4php/branches/experimental/config-adapters/src/main/php/LoggerConfigurator.php logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapter.php logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterINI.php logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterPHP.php logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterXML.php logging/log4php/branches/experimental/config-adapters/src/test/php/LoggerTest.php logging/log4php/branches/experimental/config-adapters/src/test/php/bootstrap.php logging/log4php/branches/experimental/config-adapters/src/test/php/renderers/LoggerRendererMapTest.php logging/log4php/branches/experimental/config-adapters/src/test/php/renderers/test4.properties Modified: logging/log4php/branches/experimental/config-adapters/src/main/php/Logger.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/main/php/Logger.php?rev=1172485&r1=1172484&r2=1172485&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/main/php/Logger.php (original) +++ logging/log4php/branches/experimental/config-adapters/src/main/php/Logger.php Mon Sep 19 06:47:53 2011 @@ -57,6 +57,7 @@ class Logger { 'LoggerConfigurationAdapter' => '/configurators/LoggerConfigurationAdapter.php', 'LoggerConfigurationAdapterINI' => '/configurators/LoggerConfigurationAdapterINI.php', 'LoggerConfigurationAdapterXML' => '/configurators/LoggerConfigurationAdapterXML.php', + 'LoggerConfigurationAdapterPHP' => '/configurators/LoggerConfigurationAdapterPHP.php', 'LoggerRoot' => '/LoggerRoot.php', 'LoggerAppender' => '/LoggerAppender.php', 'LoggerAppenderPool' => '/LoggerAppenderPool.php', @@ -355,7 +356,7 @@ class Logger { */ public static function getRootLogger() { if(!self::isInitialized()) { - self::initialize(); + self::configure(); } return self::getHierarchy()->getRootLogger(); } @@ -481,14 +482,11 @@ class Logger { /** * Destroy configurations for logger definitions - * - * @static - * @return boolean */ public static function resetConfiguration() { - $result = self::getHierarchy()->resetConfiguration(); + self::getHierarchy()->resetConfiguration(); + self::getHierarchy()->clear(); // TODO: clear or not? self::$initialized = false; - return $result; } /** @@ -566,12 +564,9 @@ class Logger { * that it can be included by PHP when necessary. */ public static function configure($configuration = null) { - if (!isset(self::$configurator)) { - self::$configurator = new LoggerConfigurator(); - } - self::resetConfiguration(); - self::$configurator->configure(self::getHierarchy(), $configuration); + $configurator = new LoggerConfigurator(); + $configurator->configure(self::getHierarchy(), $configuration); self::$initialized = true; } Modified: logging/log4php/branches/experimental/config-adapters/src/main/php/LoggerAppenderPool.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/main/php/LoggerAppenderPool.php?rev=1172485&r1=1172484&r2=1172485&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/main/php/LoggerAppenderPool.php (original) +++ logging/log4php/branches/experimental/config-adapters/src/main/php/LoggerAppenderPool.php Mon Sep 19 06:47:53 2011 @@ -19,7 +19,12 @@ */ /** - * Pool implmentation for LoggerAppender instances + * Pool implmentation for LoggerAppender instances. + * + * The pool is used when configuring log4php. First all appender instances + * are created in the pool. Afterward, they are linked to loggers, each + * appender can be linked to multiple loggers. This makes sure duplicate + * appenders are not created. * * @version $Revision: 795727 $ * @package log4php @@ -39,10 +44,14 @@ class LoggerAppenderPool { $name = $appender->getName(); if(empty($name)) { - trigger_error('Cannot add unnamed appender to pool.', E_USER_WARNING); + trigger_error('log4php: Cannot add unnamed appender to pool.', E_USER_WARNING); return; } + if (isset(self::$appenders[$name])) { + trigger_error("log4php: Appender [$name] already exists in pool. Overwriting existing appender.", E_USER_WARNING); + } + self::$appenders[$name] = $appender; } @@ -57,6 +66,22 @@ class LoggerAppenderPool { } /** + * Removes an appender from the pool by name. + * @param string $name Name of the appender to remove. + */ + public static function delete($name) { + unset(self::$appenders[$name]); + } + + /** + * Returns all appenders from the pool. + * @return array Array of LoggerAppender objects. + */ + public static function getAppenders() { + return self::$appenders; + } + + /** * Checks whether an appender exists in the pool. * @param string $name Name of the appender to look for. * @return boolean TRUE if the appender with the given name exists. Modified: logging/log4php/branches/experimental/config-adapters/src/main/php/LoggerConfigurator.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/main/php/LoggerConfigurator.php?rev=1172485&r1=1172484&r2=1172485&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/main/php/LoggerConfigurator.php (original) +++ logging/log4php/branches/experimental/config-adapters/src/main/php/LoggerConfigurator.php Mon Sep 19 06:47:53 2011 @@ -19,7 +19,12 @@ */ /** - * Configures log4php based on a provided configuration file or array. + * Configures log4php based on a provided configuration file or array. + * + * @package log4php + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 + * @version $Revision$ + * @since 2.2 */ class LoggerConfigurator { @@ -56,11 +61,18 @@ class LoggerConfigurator ), ); + /** Holds the appenders before they are linked to loggers. */ + private $appenders = array(); + /** - * Starts logger configuration procedure. + * Configures log4php based on the given configuration. The input can + * either be a path to the config file, or a PHP array holding the + * configuration. * - * If the config file cannot be loaded or parsed, reverts to the default - * configuration contained in {@link $defaultConfiguration}. + * If no configuration is given, or if the given configuration cannot be + * parsed for whatever reason, a warning will be issued, and log4php + * will use the default configuration contained in + * {@link $defaultConfiguration}. * * @param LoggerHierarchy $hierarchy The hierarchy on which to perform * the configuration. @@ -70,6 +82,25 @@ class LoggerConfigurator */ public function configure(LoggerHierarchy $hierarchy, $input = null) { + $config = $this->parse($input); + $this->doConfigure($hierarchy, $config); + } + + /** + * Parses the given configuration and returns the parsed configuration + * as a PHP array. Does not perform any configuration. + * + * If no configuration is given, or if the given configuration cannot be + * parsed for whatever reason, a warning will be issued, and the default + * configuration will be returned ({@link $defaultConfiguration}). + * + * @param string|array $input Either path to the config file or the + * configuration as an array. If not set, default configuration + * will be used. + * @return array The parsed configuration. + */ + public function parse($input) + { // No input - use default configuration if (!isset($input)) { $config = $this->defaultConfiguration; @@ -80,12 +111,12 @@ class LoggerConfigurator $config = $input; } - // String input - contains path to configuration file + // String input - contains path to configuration file else if (is_string($input)) { try { - $config = $this->parseConfigFile($input); - } catch (Exception $e) { - $this->warn("Failed parsing configuration file: " . $e->getMessage()); + $config = $this->parseFile($input); + } catch (LoggerException $e) { + $this->warn("Configuration failed. " . $e->getMessage() . " Using default configuration."); $config = $this->defaultConfiguration; } } @@ -95,22 +126,34 @@ class LoggerConfigurator $this->warn("Invalid configuration param given. Reverting to default configuration."); $config = $this->defaultConfiguration; } - - $this->doConfigure($hierarchy, $config); + + return $config; } + + /** + * Returns the default log4php configuration. + * @return array + */ + public function getDefaultConfiguration() { + return $this->defaultConfiguration; + } /** - * Loads the configuration file from the given URL, determines which + * Loads the configuration file from the given URL, determines which * adapter to use, converts the configuration to a PHP array and * returns it. - * + * * @param string $url Path to the config file. * @return The configuration from the config file, as a PHP array. * @throws LoggerException If the configuration file cannot be loaded, or * if the parsing fails. */ - public function parseConfigFile($url) - { + private function parseFile($url) { + + if (!file_exists($url)) { + throw new LoggerException("File not found at [$url]."); + } + $type = $this->getConfigType($url); $adapterClass = $this->adapters[$type]; @@ -158,7 +201,7 @@ class LoggerConfigurator // Configure appenders and add them to the appender pool if (isset($config['appenders']) && is_array($config['appenders'])) { foreach($config['appenders'] as $name => $appenderConfig) { - $this->configureAppender($hierarchy, $name, $appenderConfig); + $this->configureAppender($name, $appenderConfig); } } @@ -182,21 +225,28 @@ class LoggerConfigurator } } - private function configureAppender(LoggerHierarchy $hierarchy, $name, $config) { + /** + * Configures an appender based on given config and saves it to + * {@link $appenders} array so it can be later linked to loggers. + * @param string $name Appender name. + * @param array $config Appender configuration options. + */ + private function configureAppender($name, $config) { + // Parse appender class $class = $config['class']; - if (!class_exists($class)) { $this->warn("Class [$class] does not exist. Skipping appender [$name]."); return; } + // Instantiate the appender $appender = new $class($name); if (!($appender instanceof LoggerAppender)) { $this->warn("[$class] is not a valid appender class. Skipping appender [$name]."); return; } - // Parse the threshold + // Parse the appender threshold if (isset($config['threshold'])) { $threshold = LoggerLevel::toLevel($config['threshold']); if ($threshold instanceof LoggerLevel) { @@ -211,11 +261,10 @@ class LoggerConfigurator if ($appender->requiresLayout() && isset($config['layout'])) { $this->createAppenderLayout($appender, $config['layout']); } - + + // Activate and save for later linking to loggers $appender->activateOptions(); - - // Save appender in pool - LoggerAppenderPool::add($appender); + $this->appenders[$name] = $appender; } /** @@ -244,19 +293,33 @@ class LoggerConfigurator $appender->setLayout($layout); } + /** + * Configures the root logger + * @see configureLogger() + */ private function configureRootLogger(LoggerHierarchy $hierarchy, $config) { $logger = $hierarchy->getRootLogger(); $this->configureLogger($logger, $config); } - + + /** + * Configures a logger which is not root. + * @see configureLogger() + */ private function configureOtherLogger(LoggerHierarchy $hierarchy, $name, $config) { // Get logger from hierarchy (this creates it if it doesn't already exist) $logger = $hierarchy->getLogger($name); $this->configureLogger($logger, $config); } + /** + * Configures a logger. + * + * @param Logger $logger The logger to configure + * @param array $config Logger configuration options. + */ private function configureLogger(Logger $logger, $config) { - $name = $logger->getName(); + $loggerName = $logger->getName(); // Set logger level if (isset($config['level'])) { @@ -264,18 +327,18 @@ class LoggerConfigurator if (isset($level)) { $logger->setLevel($level); } else { - $this->warn("Invalid logger level [{$config['level']}] specified for logger [$name]."); + $default = $logger->getLevel(); + $this->warn("Invalid logger level [{$config['level']}] specified for logger [$loggerName]."); } } // Link appenders to logger if (isset($config['appenders'])) { foreach($config['appenders'] as $appenderName) { - $appender = LoggerAppenderPool::get($appenderName); - if (isset($appender)) { - $logger->addAppender($appender); + if (isset($this->appenders[$appenderName])) { + $logger->addAppender($this->appenders[$appenderName]); } else { - $this->warn("Nonexistnant appender [$appenderName] linked to logger [$name]."); + $this->warn("Nonexistnant appender [$appenderName] linked to logger [$loggerName]."); } } } @@ -286,11 +349,34 @@ class LoggerConfigurator if (is_bool($additivity)) { $logger->setAdditivity($additivity); } else { - $this->warn("Invalid additivity value [{$config['additivity']}] specified for logger [$name]."); + $this->warn("Invalid additivity value [{$config['additivity']}] specified for logger [$loggerName]."); } } } + /** + * Helper method which applies given options to an object which has setters + * for these options (such as appenders, layouts, etc.). + * + * For example, if options are: + * + * array( + * 'file' => '/tmp/myfile.log', + * 'append' => true + * ) + * + * + * This method will call: + * + * $object->setFile('/tmp/myfile.log') + * $object->setAppend(true) + * + * + * If required setters do not exist, it will produce a warning. + * + * @param mixed $object The object to configure. + * @param unknown_type $options + */ private function setOptions($object, $options) { foreach($options as $name => $value) { $setter = "set$name"; Modified: logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapter.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapter.php?rev=1172485&r1=1172484&r2=1172485&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapter.php (original) +++ logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapter.php Mon Sep 19 06:47:53 2011 @@ -1,5 +1,35 @@ properties = $properties; + return $properties; } /** @@ -49,21 +90,21 @@ class LoggerConfigurationAdapterINI impl */ public function convert($path) { // Load the configuration - $this->load($path); + $properties = $this->load($path); // Parse threshold - if (isset($this->properties[self::THRESHOLD_PREFIX])) { - $this->config['threshold'] = $this->properties[self::THRESHOLD_PREFIX]; + if (isset($properties[self::THRESHOLD_PREFIX])) { + $this->config['threshold'] = $properties[self::THRESHOLD_PREFIX]; } // Parse root logger - if (isset($this->properties[self::ROOT_LOGGER_PREFIX])) { - $this->parseLogger($this->properties[self::ROOT_LOGGER_PREFIX], self::ROOT_LOGGER_NAME); + if (isset($properties[self::ROOT_LOGGER_PREFIX])) { + $this->parseLogger($properties[self::ROOT_LOGGER_PREFIX], self::ROOT_LOGGER_NAME); } $appenders = array(); - foreach($this->properties as $key => $value) { + foreach($properties as $key => $value) { // Parse loggers if ($this->beginsWith($key, self::LOGGER_PREFIX)) { $name = substr($key, strlen(self::LOGGER_PREFIX)); @@ -73,7 +114,7 @@ class LoggerConfigurationAdapterINI impl // Parse additivity if ($this->beginsWith($key, self::ADDITIVITY_PREFIX)) { $name = substr($key, strlen(self::ADDITIVITY_PREFIX)); - $this->parseAdditivity($value, $name); + $this->config['loggers'][$name]['additivity'] = $value; } // Parse appenders @@ -92,65 +133,42 @@ class LoggerConfigurationAdapterINI impl /** - * Parses a logger property. + * Parses a logger definition. * * Loggers are defined in the following manner: *
 	 * log4php.logger. = [], [, , ...] 
 	 * 
* - * Where: - * - level - level to assign to the logger (optional) - * - appender-ref - name of the appenders to attach to the logger (optional) - * - * @param string $property - * @param string $loggerName + * @param string $value The configuration value (level and appender-refs). + * @param string $name Logger name. */ - private function parseLogger($property, $loggerName) { - // Values are divided by commas - $values = explode(',', $property); - - if (empty($property) || empty($values)) { + private function parseLogger($value, $name) { + // Value is divided by commas + $parts = explode(',', $value); + if (empty($value) || empty($parts)) { return; } // The first value is the logger level - $level = array_shift($values); + $level = array_shift($parts); // The remaining values are appender references $appenders = array(); - while($appender = array_shift($values)) { + while($appender = array_shift($parts)) { $appender = trim($appender); if (!empty($appender)) { $appenders[] = trim($appender); } } - $config = array( - 'level' => trim($level), - 'appenders' => $appenders - ); - - if ($loggerName == self::ROOT_LOGGER_NAME) { - $target = &$this->config['rootLogger']; - } else { - $target = &$this->config['loggers'][$loggerName]; - } - - // It is possible that the logger config array already exists - // (set when parsing additivity) so make sure not to overwrite it. - if (is_array($target)) { - $target = array_merge($target, $config); - } else { - $target = $config; - } - } - - private function parseAdditivity($value, $loggerName) { - if ($loggerName == self::ROOT_LOGGER_NAME) { - $this->config['rootLogger']['additivity'] = $value; + // Find the target configuration + if ($name == self::ROOT_LOGGER_NAME) { + $this->config['rootLogger']['level'] = trim($level); + $this->config['rootLogger']['appenders'] = $appenders; } else { - $this->config['loggers'][$loggerName]['additivity'] = $value; + $this->config['loggers'][$name]['level'] = trim($level); + $this->config['loggers'][$name]['appenders'] = $appenders; } } @@ -169,6 +187,11 @@ class LoggerConfigurationAdapterINI impl * log4php.appender.. = * * + * Appender threshold: + *
+	 * log4php.appender..threshold = 
+	 * 
+ * * Appender layout: *
 	 * log4php.appender..layout = 
@@ -182,13 +205,32 @@ class LoggerConfigurationAdapterINI impl
 	 * For example, a full appender config might look like:
 	 * 
 	 * log4php.appender.myAppender = LoggerAppenderConsole
-	 * log4php.appender.myAppender.target = STDOUT
-	 * log4php.appender.default.layout = LoggerLayoutPattern
-	 * log4php.appender.default.layout.conversionPattern = "%d %c: %m%n"
+	 * log4php.appender.myAppender.threshold = info
+	 * log4php.appender.myAppender.target = stdout
+	 * log4php.appender.myAppender.layout = LoggerLayoutPattern
+	 * log4php.appender.myAppender.layout.conversionPattern = "%d %c: %m%n"
 	 * 
* - * @param unknown_type $key - * @param unknown_type $value + * After parsing all these options, the following configuration can be + * found under $this->config['appenders']['myAppender']: + *
+	 * array(
+	 * 	'class' => LoggerAppenderConsole,
+	 * 	'threshold' => info,
+	 * 	'params' => array(
+	 * 		'target' => 'stdout'
+	 * 	),
+	 * 	'layout' => array(
+	 * 		'class' => 'LoggerAppenderConsole',
+	 * 		'params' => array(
+	 * 			'conversionPattern' => '%d %c: %m%n'
+	 * 		)
+	 * 	)
+	 * )
+	 * 
+ * + * @param string $key + * @param string $value */ private function parseAppender($key, $value) { @@ -208,30 +250,43 @@ class LoggerConfigurationAdapterINI impl return; } - // Two parts - either an appender property or layout class + // Two parts - either a parameter, a threshold or layout class else if ($count == 2) { if ($parts[1] == 'layout') { $this->config['appenders'][$name]['layout']['class'] = $value; return; + } else if ($parts[1] == 'threshold') { + $this->config['appenders'][$name]['threshold'] = $value; + return; } else { - $this->config['appenders'][$name][$parts[1]] = $value; + $this->config['appenders'][$name]['params'][$parts[1]] = $value; return; } } - // Three parts - this can only be a layout property + // Three parts - this can only be a layout parameter else if ($count == 3) { if ($parts[1] == 'layout') { - $this->config['appenders'][$name]['layout'][$parts[2]] = $value; + $this->config['appenders'][$name]['layout']['params'][$parts[2]] = $value; return; } } - trigger_error("log4php: Error in config file \"$key = $value\". Skipped this line."); + trigger_error("log4php: Don't know how to parse the following line: \"$key = $value\". Skipping."); } - - + + /** + * Parses a renderer definition. + * + * Renderers are defined as: + *
+	 * log4php.renderer. =  
+	 * 
+ * + * @param string $key log4php.renderer. + * @param string $value + */ private function parseRenderer($key, $value) { // Remove the appender prefix from key $renderedClass = substr($key, strlen(self::APPENDER_PREFIX)); @@ -240,6 +295,7 @@ class LoggerConfigurationAdapterINI impl $this->config['renderers'][] = compact('renderedClass', 'renderingClass'); } + /** Helper method. Returns true if $str begins with $sub. */ private function beginsWith($str, $sub) { return (strncmp($str, $sub, strlen($sub)) == 0); } Modified: logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterPHP.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterPHP.php?rev=1172485&r1=1172484&r2=1172485&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterPHP.php (original) +++ logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterPHP.php Mon Sep 19 06:47:53 2011 @@ -1,29 +1,81 @@ + * array( + * 'level' => 'info', + * 'appenders' => array('default') + * ), + * 'appenders' => array( + * 'default' => array( + * 'class' => 'LoggerAppenderEcho', + * 'layout' => array( + * 'class' => 'LoggerLayoutSimple' + * ) + * ) + * ) + * ) + * ?> + * + * + * @package log4php + * @subpackage configurators + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 + * @version $Revision$ + * @since 2.2 */ class LoggerConfigurationAdapterPHP implements LoggerConfigurationAdapter { - public function convert($url) - { + public function convert($url) { if (!file_exists($url)) { - throw new LoggerException("Invalid configuration file: does not exist."); + throw new LoggerException("File [$url] does not exist."); + } + + // Load the config file + $data = @file_get_contents($url); + if ($data === false) { + $error = error_get_last(); + throw new LoggerException("Error loading config file: {$error['message']}"); } - $data = @include($url); + $config = @eval('?>' . $data); if ($config === false) { $error = error_get_last(); - throw new LoggerException("Error loading PHP configuration file: " . $error['message']); + throw new LoggerException("Error parsing configuration: " . $error['message']); } if (empty($config)) { - throw new LoggerException("Invalid PHP configuration file: does not return any data."); + throw new LoggerException("Invalid configuration: empty configuration array."); } if (!is_array($config)) { - throw new LoggerException("Invalid PHP configuration file: does not return an array."); + throw new LoggerException("Invalid configuration: not an array."); } return $config; Modified: logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterXML.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterXML.php?rev=1172485&r1=1172484&r2=1172485&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterXML.php (original) +++ logging/log4php/branches/experimental/config-adapters/src/main/php/configurators/LoggerConfigurationAdapterXML.php Mon Sep 19 06:47:53 2011 @@ -1,7 +1,31 @@ validateXML($config); -// libxml_clear_errors(); -// libxml_use_internal_errors($internal); - // Load XML - $xml = simplexml_load_string($config); + $xml = simplexml_load_file($url); if ($xml === false) { - throw new LoggerException("XML file contains errors."); + throw new LoggerException("Error loading confuguration file."); } return $xml; } /** - * DOMDocument is used here for validation because SimpleXML doesn't - * implement this feature. - * @param string $input The configuration XML. - */ - private function validateXML($url) { - $schema = dirname(__FILE__) . self::SCHEMA_PATH; - try { - $dom = new DOMDocument(); - $dom->loadXML($url); - } catch(Exception $e) { - throw new LoggerException("Failed parsing XML configuration file."); - } - - $success = $dom->schemaValidate($schema); - if ($success === false) { - $errors = libxml_get_errors(); - foreach($errors as $error) { - $message = trim($error->message) . " On line {$error->line} of the configuration file."; - $this->warn($message); - } - throw new LoggerException("The XML configuration file failed validation."); - } - } - - /** * Parses the node. */ private function parseConfiguration(SimpleXMLElement $xml) { @@ -115,9 +100,8 @@ class LoggerConfigurationAdapterXML impl $appender = array(); $appender['class'] = $this->getAttributeValue($node, 'class'); - $attrs = $node->attributes(); - if (isset($attrs['threshold'])) { - $appender['threshold'] = (string) $attrs['threshold']; + if (isset($node['threshold'])) { + $appender['threshold'] = $this->getAttributeValue($node, 'threshold'); } if (isset($node->layout)) { @@ -147,13 +131,17 @@ class LoggerConfigurationAdapterXML impl return $layout; } /** Parses any child nodes returning them in an array. */ - private function parseParameters($node) { + private function parseParameters($paramsNode) { $params = array(); - foreach($node->param as $paramNode) { - $attrs = $paramNode->attributes(); - $name = (string) $attrs['name']; - $value = (string) $attrs['value']; + foreach($paramsNode->param as $paramNode) { + if (empty($paramNode['name'])) { + $this->warn("Found parameter node without a name. Skipping parameter."); + continue; + } + + $name = $this->getAttributeValue($paramNode, 'name'); + $value = $this->getAttributeValue($paramNode, 'value'); $params[$name] = $value; } @@ -180,18 +168,28 @@ class LoggerConfigurationAdapterXML impl /** Parses a node. */ private function parseLogger(SimpleXMLElement $node) { $logger = array(); - $attributes = $node->attributes(); - $name = (string) $attributes['name']; + // Check logger name exists (mandatory because it is used as the array key) + if (empty($node['name'])) { + $this->warn("Found logger without a 'name' attribute. All loggers must be named. Skipping."); + return; + } + + $name = (string) $node['name']; if (isset($node->level)) { $logger['level'] = $this->getAttributeValue($node->level, 'value'); } + if (isset($node['additivity'])) { + $logger['additivity'] = $this->getAttributeValue($node, 'additivity'); + } + $logger['appenders'] = $this->parseAppenderReferences($node, $name); + // Check for duplicate loggers if (isset($this->config['loggers'][$name])) { - $this->warn("Duplicate logger definition for $name. Overwriting."); + $this->warn("Duplicate logger definition [$name]. Overwriting."); } $this->config['loggers'][$name] = $logger; Added: logging/log4php/branches/experimental/config-adapters/src/test/php/LoggerConfiguratorTest.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/LoggerConfiguratorTest.php?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/LoggerConfiguratorTest.php (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/LoggerConfiguratorTest.php Mon Sep 19 06:47:53 2011 @@ -0,0 +1,96 @@ +assertSame($expected, $actual); + + $appenders = Logger::getRootLogger()->getAllAppenders(); + $this->assertInternalType('array', $appenders); + $this->assertEquals(count($appenders), 1); + $this->assertSame('default', $appenders[0]->getName()); + + $appender = $appenders[0]; + $this->assertInstanceOf('LoggerAppenderEcho', $appender); + + $layout = $appender->getLayout(); + $this->assertInstanceOf('LoggerLayoutSimple', $layout); + + $root = Logger::getRootLogger(); + $appenders = $root->getAllAppenders(); + $this->assertInternalType('array', $appenders); + $this->assertEquals(count($appenders), 1); + + $actual = $root->getLevel(); + $expected = LoggerLevel::getLevelInfo(); + $this->assertSame($expected, $actual); + } + + /** + * Test that an error is reported when config file is not found. + * @expectedException PHPUnit_Framework_Error + * @expectedExceptionMessage log4php: Configuration failed. File not found + */ + public function testNonexistantFile() { + Logger::configure('hopefully/this/path/doesnt/exist/config.xml'); + + } + + /** Test correct fallback to the default configuration. */ + public function testNonexistantFileFallback() { + @Logger::configure('hopefully/this/path/doesnt/exist/config.xml'); + $this->testDefaultConfig(); + } + + public function testAppendersWithLayout() { + Logger::configure(array( + 'rootLogger' => array( + 'appenders' => array('app1', 'app2') + ), + 'appenders' => array( + 'app1' => array( + 'class' => 'LoggerAppenderEcho', + 'layout' => array( + 'class' => 'LoggerLayoutSimple' + ) + ), + 'app2' => array( + 'class' => 'LoggerAppenderEcho', + 'layout' => array( + 'class' => 'LoggerLayoutPattern', + 'conversionPattern' => 'message: %m%n' + ) + ), + ) + )); + + ob_start(); + Logger::getRootLogger()->info('info'); + $actual = ob_get_contents(); + ob_end_clean(); + + $expected = "INFO - info" . PHP_EOL . "message: info" . PHP_EOL; + $this->assertSame($expected, $actual); + } + } \ No newline at end of file Modified: logging/log4php/branches/experimental/config-adapters/src/test/php/LoggerTest.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/LoggerTest.php?rev=1172485&r1=1172484&r2=1172485&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/LoggerTest.php (original) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/LoggerTest.php Mon Sep 19 06:47:53 2011 @@ -55,7 +55,7 @@ class LoggerTest extends PHPUnit_Framewo } public function testCanLogToAllLevels() { - Logger::configure('LoggerTest.properties'); + Logger::configure(dirname(__FILE__) . '/LoggerTest.properties'); $logger = Logger::getLogger('mylogger'); ob_start(); @@ -78,7 +78,7 @@ class LoggerTest extends PHPUnit_Framewo } public function testIsEnabledFor() { - Logger::configure('LoggerTest.properties'); + Logger::configure(dirname(__FILE__) . '/LoggerTest.properties'); $logger = Logger::getLogger('mylogger'); @@ -97,34 +97,10 @@ class LoggerTest extends PHPUnit_Framewo self::assertEquals(0, count(Logger::getCurrentLoggers())); - Logger::configure('LoggerTest.properties'); - Logger::initialize(); + Logger::configure(dirname(__FILE__) . '/LoggerTest.properties'); self::assertEquals(1, count(Logger::getCurrentLoggers())); $list = Logger::getCurrentLoggers(); self::assertEquals('mylogger', $list[0]->getName()); } - - public function testConfigure() { - Logger::resetConfiguration(); - Logger::configure(); - self::assertEquals('LoggerConfiguratorBasic', Logger::getConfigurationClass()); - self::assertEquals(null, Logger::getConfigurationFile()); - - Logger::configure(null, 'MyLoggerClass'); - self::assertEquals('MyLoggerClass', Logger::getConfigurationClass()); - self::assertEquals(null, Logger::getConfigurationFile()); - - Logger::configure('log4php.xml'); - self::assertEquals('LoggerConfiguratorXml', Logger::getConfigurationClass()); - self::assertEquals('log4php.xml', Logger::getConfigurationFile()); - - Logger::configure('log4php.xml'); - self::assertEquals('LoggerConfiguratorXml', Logger::getConfigurationClass()); - self::assertEquals('log4php.xml', Logger::getConfigurationFile()); - - Logger::configure('log4php.properties'); - self::assertEquals('LoggerConfiguratorIni', Logger::getConfigurationClass()); - self::assertEquals('log4php.properties', Logger::getConfigurationFile()); - - } + } Modified: logging/log4php/branches/experimental/config-adapters/src/test/php/bootstrap.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/bootstrap.php?rev=1172485&r1=1172484&r2=1172485&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/bootstrap.php (original) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/bootstrap.php Mon Sep 19 06:47:53 2011 @@ -26,4 +26,12 @@ error_reporting(E_ALL | E_STRICT); date_default_timezone_set('Europe/London'); +// Define a temp dir where tests may write to +$tmpDir = dirname(__FILE__) . '/../../../../target/temp/phpunit'; +if (!is_dir($tmpDir)) { + mkdir($tmpDir, 0777, true); +} +define('PHPUNIT_TEMP_DIR', realpath($tmpDir)); + require dirname(__FILE__) . '/../../main/php/Logger.php'; + Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterINITest.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterINITest.php?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterINITest.php (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterINITest.php Mon Sep 19 06:47:53 2011 @@ -0,0 +1,117 @@ + 'debug', + 'rootLogger' => array( + 'level' => 'DEBUG', + 'appenders' => array('default'), + ), + 'appenders' => array( + 'default' => array( + 'class' => 'LoggerAppenderEcho', + 'layout' => array( + 'class' => 'LoggerLayoutTTCC', + ), + ), + 'file' => array( + 'class' => 'LoggerAppenderDailyFile', + 'layout' => array( + 'class' => 'LoggerLayoutPattern', + 'params' => array( + 'conversionPattern' => '%d{ISO8601} [%p] %c: %m (at %F line %L)%n', + ), + ), + 'params' => array( + 'datePattern' => 'Ymd', + 'file' => 'target/examples/daily_%s.log', + ), + 'threshold' => 'warn' + ), + ), + 'loggers' => array( + 'foo' => array( + 'level' => 'warn', + 'appenders' => array('default'), + ), + 'foo.bar' => array( + 'level' => 'debug', + 'appenders' => array('file'), + 'additivity' => 'true', + ), + 'foo.bar.baz' => array( + 'level' => 'trace', + 'appenders' => array('default', 'file'), + 'additivity' => 'false', + ), + ), + 'renderers' => array( + array( + 'renderedClass' => 'Fruit', + 'renderingClass' => 'FruitRenderer', + ), + array( + 'renderedClass' => 'Beer', + 'renderingClass' => 'BeerRenderer', + ), + ), + ); + + public function testConfig() { + $url = dirname(__FILE__) . '/config1.ini'; + $adapter = new LoggerConfigurationAdapterINI(); + $actual = $adapter->convert($url); + + $this->assertSame($this->expected1, $actual); + } + + /** + * Test exception is thrown when file cannot be found. + * @expectedException LoggerException + * @expectedExceptionMessage File [you/will/never/find/me.ini] does not exist. + */ + public function testNonExistantFileException() { + $adapter = new LoggerConfigurationAdapterINI(); + $adapter->convert('you/will/never/find/me.ini'); + } + + /** + * Test exception is thrown when file is not a valid ini file. + * @expectedException LoggerException + * @expectedExceptionMessage Error parsing configuration file: syntax error, unexpected $end + */ + public function testInvalidFileException() { + $url = dirname(__FILE__) . '/config2.ini'; + $adapter = new LoggerConfigurationAdapterINI(); + $adapter->convert($url); + } + + /** + * Test a warning is triggered when configurator doesn't understand a line. + * @expectedException PHPUnit_Framework_Error + * @expectedExceptionMessage log4php: Don't know how to parse the following line: "log4php.appender.default.layout.param.bla = LoggerLayoutTTCC". Skipping. + */ + public function testInvalidLineWarning1() { + $url = dirname(__FILE__) . '/config3.ini'; + $adapter = new LoggerConfigurationAdapterINI(); + $adapter->convert($url); + } + + /** + * Test a warning is triggered when configurator doesn't understand a line. + * @ expectedException PHPUnit_Framework_Error + * @ expectedExceptionMessage log4php: Don't know how to parse the following line: "log4php.appender.default.layout.param.bla = LoggerLayoutTTCC". Skipping. + */ + public function testInvalidLineWarning2() { + $url = dirname(__FILE__) . '/config4.ini'; + $adapter = new LoggerConfigurationAdapterINI(); + $adapter->convert($url); + } +} + +?> \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterPHPTest.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterPHPTest.php?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterPHPTest.php (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterPHPTest.php Mon Sep 19 06:47:53 2011 @@ -0,0 +1,77 @@ + array( + 'level' => 'info', + 'appenders' => array('default') + ), + 'appenders' => array( + 'default' => array( + 'class' => 'LoggerAppenderEcho', + 'layout' => array( + 'class' => 'LoggerLayoutSimple' + ) + ) + ) + ); + + public function testConfig() { + $url = dirname(__FILE__) . '/config1.php'; + $adapter = new LoggerConfigurationAdapterPHP(); + $actual = $adapter->convert($url); + + $this->assertSame($this->expected1, $actual); + } + + /** + * Test exception is thrown when file cannot be found. + * @expectedException LoggerException + * @expectedExceptionMessage File [you/will/never/find/me.conf] does not exist. + */ + public function testNonExistantFileWarning() { + $adapter = new LoggerConfigurationAdapterPHP(); + $adapter->convert('you/will/never/find/me.conf'); + } + + /** + * Test exception is thrown when file is not valid. + * @expectedException LoggerException + * @expectedExceptionMessage Error parsing configuration: syntax error + */ + public function testInvalidFileWarning() { + $url = dirname(__FILE__) . '/config2.php'; + $adapter = new LoggerConfigurationAdapterPHP(); + $adapter->convert($url); + } + + /** + * Test exception is thrown when the configuration is empty. + * @expectedException LoggerException + * @expectedExceptionMessage Invalid configuration: empty configuration array. + */ + public function testEmptyConfigWarning() { + $url = dirname(__FILE__) . '/config3.php'; + $adapter = new LoggerConfigurationAdapterPHP(); + $adapter->convert($url); + } + + /** + * Test exception is thrown when the configuration does not contain an array. + * @expectedException LoggerException + * @expectedExceptionMessage Invalid configuration: not an array. + */ + public function testInvalidConfigWarning() { + $url = dirname(__FILE__) . '/config4.php'; + $adapter = new LoggerConfigurationAdapterPHP(); + $adapter->convert($url); + } + + +} + +?> \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php Mon Sep 19 06:47:53 2011 @@ -0,0 +1,144 @@ + array( + 'default' => array( + 'class' => 'LoggerAppenderEcho', + 'layout' => array( + 'class' => 'LoggerLayoutTTCC', + ), + 'filters' => array( + array( + 'class' => 'LoggerFilterLevelRange', + 'params' => array( + 'levelMin' => 'ERROR', + 'levelMax' => 'FATAL', + 'acceptOnMatch' => 'false', + ), + ), + array( + 'class' => 'LoggerFilterDenyAll', + ), + ), + ), + 'file' => array( + 'class' => 'LoggerAppenderDailyFile', + 'layout' => array( + 'class' => 'LoggerLayoutPattern', + 'params' => array( + 'conversionPattern' => '%d{ISO8601} [%p] %c: %m (at %F line %L)%n', + ), + ), + 'params' => array( + 'datePattern' => 'Ymd', + 'file' => 'target/examples/daily_%s.log', + ), + 'threshold' => 'warn' + ), + ), + 'loggers' => array( + 'foo.bar.baz' => array( + 'level' => 'trace', + 'additivity' => 'false', + 'appenders' => array('default'), + ), + 'foo.bar' => array( + 'level' => 'debug', + 'additivity' => 'true', + 'appenders' => array('file'), + ), + 'foo' => array( + 'level' => 'warn', + 'appenders' => array('default', 'file'), + ), + ), + 'renderers' => array( + array( + 'renderedClass' => 'Fruit', + 'renderingClass' => 'FruitRenderer', + ), + array( + 'renderedClass' => 'Beer', + 'renderingClass' => 'BeerRenderer', + ), + ), + 'threshold' => 'debug', + 'rootLogger' => array( + 'level' => 'DEBUG', + 'appenders' => array('default'), + ), + ); + + public function setUp() { + Logger::resetConfiguration(); + } + + public function tearDown() { + Logger::resetConfiguration(); + } + + public function testConversion() { + $url = dirname(__FILE__) . '/config1.xml'; + $adapter = new LoggerConfigurationAdapterXML(); + $actual = $adapter->convert($url); + $this->assertEquals($this->expected1, $actual); + } + + /** + * Test exception is thrown when file cannot be found. + * @expectedException LoggerException + * @expectedExceptionMessage File [you/will/never/find/me.conf] does not exist. + */ + public function testNonExistantFile() { + $adapter = new LoggerConfigurationAdapterXML(); + $adapter->convert('you/will/never/find/me.conf'); + } + + /** + * Test exception is thrown when file contains invalid XML. + * @ expectedException LoggerException + * @ expectedExceptionMessage Cannot load config file + */ + public function testInvalidXMLFile() { + // TODO: fix error reporting for XML files + //$url = dirname(__FILE__) . '/config4.xml'; + //$adapter = new LoggerConfigurationAdapterXML(); + //$adapter->convert($url); + } + + /** + * Test that a warning is triggered when two loggers with the same name + * are defined. + * @expectedException PHPUnit_Framework_Error + * @expectedExceptionMessage log4php: Duplicate logger definition [foo]. Overwriting + */ + public function testDuplicateLoggerWarning() { + $url = dirname(__FILE__) . '/config3.xml'; + $adapter = new LoggerConfigurationAdapterXML(); + $adapter->convert($url); + } + + + /** + * Test that when two loggers with the same name are defined, the second + * one will overwrite the first. + */ + public function testDuplicateLoggerConfig() { + $url = dirname(__FILE__) . '/config3.xml'; + $adapter = new LoggerConfigurationAdapterXML(); + + // Supress the warning so that test can continue + $config = @$adapter->convert($url); + + // Second definition of foo has level set to warn (the first to info) + $this->assertEquals('warn', $config['loggers']['foo']['level']); + } +} + +?> \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.ini URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.ini?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.ini (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.ini Mon Sep 19 06:47:53 2011 @@ -0,0 +1,24 @@ +log4php.rootLogger = DEBUG, default + +log4php.appender.default = LoggerAppenderEcho +log4php.appender.default.layout = LoggerLayoutTTCC + +log4php.appender.file = LoggerAppenderDailyFile +log4php.appender.file.layout = LoggerLayoutPattern +log4php.appender.file.layout.conversionPattern =%d{ISO8601} [%p] %c: %m (at %F line %L)%n +log4php.appender.file.datePattern = Ymd +log4php.appender.file.file = target/examples/daily_%s.log +log4php.appender.file.threshold = warn + +log4php.logger.foo = warn, default + +log4php.logger.foo.bar = debug, file +log4php.additivity.foo.bar = true + +log4php.logger.foo.bar.baz = trace, default, file +log4php.additivity.foo.bar.baz = false + +log4php.renderer.Fruit = FruitRenderer +log4php.renderer.Beer = BeerRenderer + +log4php.threshold = debug Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.php?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.php (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.php Mon Sep 19 06:47:53 2011 @@ -0,0 +1,19 @@ + array( + 'level' => 'info', + 'appenders' => array('default') + ), + 'appenders' => array( + 'default' => array( + 'class' => 'LoggerAppenderEcho', + 'layout' => array( + 'class' => 'LoggerLayoutSimple' + ) + ) + ) +) +; + +?> \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.xml URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.xml?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.xml (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config1.xml Mon Sep 19 06:47:53 2011 @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.ini URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.ini?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.ini (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.ini Mon Sep 19 06:47:53 2011 @@ -0,0 +1,5 @@ +#not valid because it doesn't have a line break at the end. +log4php.rootLogger = DEBUG, default + +log4php.appender.default = LoggerAppenderEcho +log4php.appender.default.layout = LoggerLayoutTTCC \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.php?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.php (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.php Mon Sep 19 06:47:53 2011 @@ -0,0 +1,20 @@ + array( + 'level' => 'info', + 'appenders' => array('default') + ), + 'appenders' => array( + 'default' => array( + 'class' => 'LoggerAppenderEcho', + 'layout' => array( + 'class' => 'LoggerLayoutSimple' + ) + ) + ) + +// Invalid file - no closing brace. + +?> \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.xml URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.xml?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.xml (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config2.xml Mon Sep 19 06:47:53 2011 @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.ini URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.ini?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.ini (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.ini Mon Sep 19 06:47:53 2011 @@ -0,0 +1,7 @@ +log4php.rootLogger = DEBUG, default + +log4php.appender.default = LoggerAppenderEcho + +# invalid appender line should trigger warning +log4php.appender.default.layout.param.bla = LoggerLayoutTTCC + \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.php?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.php (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.php Mon Sep 19 06:47:53 2011 @@ -0,0 +1,5 @@ + \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.xml URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.xml?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.xml (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config3.xml Mon Sep 19 06:47:53 2011 @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.ini URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.ini?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.ini (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.ini Mon Sep 19 06:47:53 2011 @@ -0,0 +1,7 @@ +log4php.rootLogger = DEBUG, default + +log4php.appender.default = LoggerAppenderEcho + +# invalid appender line should trigger warning +log4php.appender.default.not-layout.param = LoggerLayoutTTCC + \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.php?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.php (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.php Mon Sep 19 06:47:53 2011 @@ -0,0 +1,6 @@ + \ No newline at end of file Added: logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.xml URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.xml?rev=1172485&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.xml (added) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/configurators/config4.xml Mon Sep 19 06:47:53 2011 @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Modified: logging/log4php/branches/experimental/config-adapters/src/test/php/renderers/LoggerRendererMapTest.php URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/renderers/LoggerRendererMapTest.php?rev=1172485&r1=1172484&r2=1172485&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/renderers/LoggerRendererMapTest.php (original) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/renderers/LoggerRendererMapTest.php Mon Sep 19 06:47:53 2011 @@ -46,7 +46,6 @@ class LoggerRendererMapTest extends PHPU public function testFindAndRender() { $fruit = new Fruit3(); Logger::configure(dirname(__FILE__).'/test4.properties'); - Logger::initialize(); $hierarchy = Logger::getHierarchy(); $map = $hierarchy->getRendererMap(); @@ -57,7 +56,6 @@ class LoggerRendererMapTest extends PHPU public function testFindAndRenderDescendants() { $fruit = new Fruit3Descendant(); Logger::configure(dirname(__FILE__).'/test4.properties'); - Logger::initialize(); $hierarchy = Logger::getHierarchy(); $map = $hierarchy->getRendererMap(); @@ -68,7 +66,6 @@ class LoggerRendererMapTest extends PHPU public function testGetByObject() { $fruit = new Fruit3(); Logger::configure(dirname(__FILE__).'/test4.properties'); - Logger::initialize(); $hierarchy = Logger::getHierarchy(); $map = $hierarchy->getRendererMap(); @@ -78,7 +75,6 @@ class LoggerRendererMapTest extends PHPU public function testGetByClassName() { Logger::configure(dirname(__FILE__).'/test4.properties'); - Logger::initialize(); $hierarchy = Logger::getHierarchy(); $map = $hierarchy->getRendererMap(); @@ -89,14 +85,14 @@ class LoggerRendererMapTest extends PHPU public function testUsage() { Logger::resetConfiguration(); Logger::configure(dirname(__FILE__).'/test4.properties'); - Logger::initialize(); $logger = Logger::getRootLogger(); ob_start(); - $logger->error(new Fruit3()); - $v = ob_get_contents(); + $logger->warn(new Fruit3()); + $actual = ob_get_contents(); ob_end_clean(); - self::assertEquals("ERROR - test1,test2,test3" . PHP_EOL, $v); + $expected = "WARN - test1,test2,test3" . PHP_EOL; + self::assertEquals($expected, $actual); } } Modified: logging/log4php/branches/experimental/config-adapters/src/test/php/renderers/test4.properties URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/test/php/renderers/test4.properties?rev=1172485&r1=1172484&r2=1172485&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/test/php/renderers/test4.properties (original) +++ logging/log4php/branches/experimental/config-adapters/src/test/php/renderers/test4.properties Mon Sep 19 06:47:53 2011 @@ -19,9 +19,9 @@ log4php.appender.default = LoggerAppende log4php.appender.default.layout = LoggerLayoutSimple log4php.appender.default.threshold = WARN -log4php.appender.blub2 = LoggerAppenderEcho +log4php.appender.rendr2 = LoggerAppenderEcho log4php.appender.rendr2.layout = LoggerLayoutSimple -log4php.appender.rendr2.threshold = INFO +log4php.appender.rendr2.threshold = ERROR log4php.threshold = WARN log4php.rootLogger = WARN, default, rendr2