logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ihabu...@apache.org
Subject svn commit: r1212319 - in /logging/log4php/trunk/src: changes/changes.xml main/php/LoggerConfigurator.php main/php/LoggerLevel.php test/php/LoggerConfiguratorTest.php
Date Fri, 09 Dec 2011 10:18:38 GMT
Author: ihabunek
Date: Fri Dec  9 10:18:37 2011
New Revision: 1212319

URL: http://svn.apache.org/viewvc?rev=1212319&view=rev
Log:
LOG4PHP-162: Warning for invalid appender threshold level never called

Modified:
    logging/log4php/trunk/src/changes/changes.xml
    logging/log4php/trunk/src/main/php/LoggerConfigurator.php
    logging/log4php/trunk/src/main/php/LoggerLevel.php
    logging/log4php/trunk/src/test/php/LoggerConfiguratorTest.php

Modified: logging/log4php/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/changes/changes.xml?rev=1212319&r1=1212318&r2=1212319&view=diff
==============================================================================
--- logging/log4php/trunk/src/changes/changes.xml (original)
+++ logging/log4php/trunk/src/changes/changes.xml Fri Dec  9 10:18:37 2011
@@ -21,6 +21,7 @@
 	</properties>
 	<body>
 	    <release version="2.2.0" date="SVN">
+	    	<action date="2011-12-09" type="fix" issue="LOG4PHP-162" dev="Ivan Habunek">Warning
for invalid appender threshold level never called.</action>
 	    	<action date="2011-12-08" type="fix" issue="LOG4PHP-114" dev="Ivan Habunek">Order
of params in LoggerAppenderDailyFile configuration is significant.</action>
 	    	<action date="2011-12-08" type="update" issue="LOG4PHP-154" dev="Ivan Habunek">Rewritten
LoggerAppenderSocket to use a layout.</action>
 	    	<action date="2011-12-04" type="add" issue="LOG4PHP-160" dev="Ivan Habunek" due-to="Florian
Semm" due-to-email="florian dot semm at gmx dot de">Appeneders should use a default layout
is no layout is specified in configuration</action>

Modified: logging/log4php/trunk/src/main/php/LoggerConfigurator.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/LoggerConfigurator.php?rev=1212319&r1=1212318&r2=1212319&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/LoggerConfigurator.php (original)
+++ logging/log4php/trunk/src/main/php/LoggerConfigurator.php Fri Dec  9 10:18:37 2011
@@ -193,7 +193,7 @@ class LoggerConfigurator
 			if (isset($threshold)) {
 				$hierarchy->setThreshold($threshold);
 			} else {
-				$this->warn("Invalid threshold {$config['threshold']} specified.");
+				$this->warn("Invalid threshold value [{$config['threshold']}] specified. Ignoring
threshold definition.");
 			}
 		}
 		
@@ -295,8 +295,7 @@ class LoggerConfigurator
 			if ($threshold instanceof LoggerLevel) {
 				$appender->setThreshold($threshold);
 			} else {
-				$default = $appender->getThreshold();
-				$this->warn("Invalid threshold value [{$config['threshold']}] specified for appender
[$name]. Reverting to default value [$default].");
+				$this->warn("Invalid threshold value [{$config['threshold']}] specified for appender
[$name]. Ignoring threshold definition.");
 			}
 		}
 		
@@ -416,7 +415,7 @@ class LoggerConfigurator
 				$logger->setLevel($level);
 			} else {
 				$default = $logger->getLevel();
-				$this->warn("Invalid logger level [{$config['level']}] specified for logger [$loggerName].");
+				$this->warn("Invalid level value [{$config['level']}] specified for logger [$loggerName].
Ignoring level definition.");
 			}
 		}
 		
@@ -437,7 +436,7 @@ class LoggerConfigurator
 			if (is_bool($additivity)) {
 				$logger->setAdditivity($additivity);
 			} else {
-				$this->warn("Invalid additivity value [{$config['additivity']}] specified for logger
[$loggerName].");
+				$this->warn("Invalid additivity value [{$config['additivity']}] specified for logger
[$loggerName]. Ignoring additivity setting.");
 			}
 		}
 	}

Modified: logging/log4php/trunk/src/main/php/LoggerLevel.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/LoggerLevel.php?rev=1212319&r1=1212318&r2=1212319&view=diff
==============================================================================
--- logging/log4php/trunk/src/main/php/LoggerLevel.php (original)
+++ logging/log4php/trunk/src/main/php/LoggerLevel.php Fri Dec  9 10:18:37 2011
@@ -228,40 +228,37 @@ class LoggerLevel {
 	}
 
 	/**
-	 * Convert the string passed as argument to a level. If the
-	 * conversion fails, then this method returns a DEBUG Level.
+	 * Convert the input argument to a level. If the conversion fails, then 
+	 * this method returns the provided default level.
 	 *
-	 * @param mixed $arg
-	 * @param LoggerLevel $default
+	 * @param mixed $arg The value to convert to level.
+	 * @param LoggerLevel $default Value to return if conversion is not possible.
+	 * @return LoggerLevel 
 	 */
 	public static function toLevel($arg, $defaultLevel = null) {
-		if($defaultLevel === null) {
-			return self::toLevel($arg, self::getLevelDebug());
+		if(is_int($arg)) {
+			switch($arg) {
+				case self::ALL:	return self::getLevelAll();
+				case self::TRACE: return self::getLevelTrace();
+				case self::DEBUG: return self::getLevelDebug();
+				case self::INFO: return self::getLevelInfo();
+				case self::WARN: return self::getLevelWarn();
+				case self::ERROR: return self::getLevelError();
+				case self::FATAL: return self::getLevelFatal();
+				case self::OFF:	return self::getLevelOff();
+				default: return $defaultLevel;
+			}
 		} else {
-			if(is_int($arg)) {
-				switch($arg) {
-					case self::ALL:	return self::getLevelAll();
-					case self::TRACE: return self::getLevelTrace();
-					case self::DEBUG: return self::getLevelDebug();
-					case self::INFO: return self::getLevelInfo();
-					case self::WARN: return self::getLevelWarn();
-					case self::ERROR: return self::getLevelError();
-					case self::FATAL: return self::getLevelFatal();
-					case self::OFF:	return self::getLevelOff();
-					default: return $defaultLevel;
-				}
-			} else {
-				switch(strtoupper($arg)) {
-					case 'ALL':	return self::getLevelAll();
-					case 'TRACE': return self::getLevelTrace();
-					case 'DEBUG': return self::getLevelDebug();
-					case 'INFO': return self::getLevelInfo();
-					case 'WARN': return self::getLevelWarn();
-					case 'ERROR': return self::getLevelError();
-					case 'FATAL': return self::getLevelFatal();
-					case 'OFF':	return self::getLevelOff();
-					default: return $defaultLevel;
-				}
+			switch(strtoupper($arg)) {
+				case 'ALL':	return self::getLevelAll();
+				case 'TRACE': return self::getLevelTrace();
+				case 'DEBUG': return self::getLevelDebug();
+				case 'INFO': return self::getLevelInfo();
+				case 'WARN': return self::getLevelWarn();
+				case 'ERROR': return self::getLevelError();
+				case 'FATAL': return self::getLevelFatal();
+				case 'OFF':	return self::getLevelOff();
+				default: return $defaultLevel;
 			}
 		}
 	}

Modified: logging/log4php/trunk/src/test/php/LoggerConfiguratorTest.php
URL: http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/LoggerConfiguratorTest.php?rev=1212319&r1=1212318&r2=1212319&view=diff
==============================================================================
--- logging/log4php/trunk/src/test/php/LoggerConfiguratorTest.php (original)
+++ logging/log4php/trunk/src/test/php/LoggerConfiguratorTest.php Fri Dec  9 10:18:37 2011
@@ -276,4 +276,153 @@
  		$expected = "INFO - info" . PHP_EOL . "message: info" . PHP_EOL;
   		$this->assertSame($expected, $actual);
  	}
+ 	
+  	public function testThreshold()
+ 	{
+ 		Logger::configure(array(
+ 			'threshold' => 'WARN',
+ 			'rootLogger' => array(
+ 				'appenders' => array('default')
+ 			),
+ 			'appenders' => array(
+ 				'default' => array(
+ 					'class' => 'LoggerAppenderEcho',
+ 				),
+ 			) 
+ 		));
+ 		
+ 		$actual = Logger::getHierarchy()->getThreshold();
+ 		$expected = LoggerLevel::getLevelWarn();
+ 		
+ 		self::assertSame($expected, $actual);
+ 	}
+ 	
+ 	/**
+ 	* @expectedException PHPUnit_Framework_Error
+ 	* @expectedExceptionMessage Invalid threshold value [FOO] specified. Ignoring threshold
definition.
+ 	*/
+  	public function testInvalidThreshold()
+ 	{
+ 		Logger::configure(array(
+ 			'threshold' => 'FOO',
+ 			'rootLogger' => array(
+ 				'appenders' => array('default')
+ 			),
+ 			'appenders' => array(
+ 				'default' => array(
+ 					'class' => 'LoggerAppenderEcho',
+ 				),
+ 			) 
+ 		));
+ 	}
+ 	
+ 	public function testAppenderThreshold()
+ 	{
+ 		Logger::configure(array(
+ 			'rootLogger' => array(
+ 				'appenders' => array('default')
+ 			),
+ 			'appenders' => array(
+ 				'default' => array(
+ 					'class' => 'LoggerAppenderEcho',
+ 					'threshold' => 'INFO'
+ 				),
+ 			) 
+ 		));
+ 		
+ 		$actual = Logger::getRootLogger()->getAppender('default')->getThreshold();
+ 		$expected = LoggerLevel::getLevelInfo();
+
+ 		self::assertSame($expected, $actual);
+ 	}
+ 	
+ 	/**
+ 	 * @expectedException PHPUnit_Framework_Error
+ 	 * @expectedExceptionMessage Invalid threshold value [FOO] specified for appender [default].
Ignoring threshold definition.
+ 	 */
+ 	public function testAppenderInvalidThreshold()
+ 	{
+ 		Logger::configure(array(
+ 			'rootLogger' => array(
+ 				'appenders' => array('default')
+ 			),
+ 			'appenders' => array(
+ 				'default' => array(
+ 					'class' => 'LoggerAppenderEcho',
+ 					'threshold' => 'FOO'
+ 				),
+ 			) 
+ 		));
+ 	}
+ 	
+ 	public function testLoggerThreshold()
+ 	{
+ 		Logger::configure(array(
+ 			'rootLogger' => array(
+ 				'appenders' => array('default'),
+ 				'level' => 'ERROR'
+ 			),
+ 			'loggers' => array(
+ 				'default' => array(
+ 					'appenders' => array('default'),
+ 		 			'level' => 'WARN'
+ 				)
+ 			),
+ 			'appenders' => array(
+ 				'default' => array(
+ 					'class' => 'LoggerAppenderEcho',
+ 				),
+ 			) 
+ 		));
+ 		
+ 		// Check root logger
+ 		$actual = Logger::getRootLogger()->getLevel();
+ 		$expected = LoggerLevel::getLevelError();
+ 		self::assertSame($expected, $actual);
+ 		
+ 		// Check default logger
+ 		$actual = Logger::getLogger('default')->getLevel();
+ 		$expected = LoggerLevel::getLevelWarn();
+ 		self::assertSame($expected, $actual);
+ 	}
+ 	
+ 	/**
+ 	 * @expectedException PHPUnit_Framework_Error
+ 	 * @expectedExceptionMessage Invalid level value [FOO] specified for logger [default].
Ignoring level definition.
+ 	 */
+ 	public function testInvalidLoggerThreshold()
+ 	{
+ 		Logger::configure(array(
+ 			'loggers' => array(
+ 				'default' => array(
+ 					'appenders' => array('default'),
+ 		 			'level' => 'FOO'
+ 				)
+ 			),
+ 			'appenders' => array(
+ 				'default' => array(
+ 					'class' => 'LoggerAppenderEcho',
+ 				),
+ 			) 
+ 		));
+ 	}
+ 	
+ 	/**
+ 	 * @expectedException PHPUnit_Framework_Error
+ 	 * @expectedExceptionMessage Invalid level value [FOO] specified for logger [root]. Ignoring
level definition.
+ 	 */
+  	public function testInvalidRootLoggerThreshold()
+ 	{
+ 		Logger::configure(array(
+ 			'rootLogger' => array(
+ 				'appenders' => array('default'),
+ 				'level' => 'FOO'
+ 			),
+ 			'appenders' => array(
+ 				'default' => array(
+ 					'class' => 'LoggerAppenderEcho',
+ 				),
+ 			) 
+ 		));
+ 	}
  }
\ No newline at end of file



Mime
View raw message