You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4php-dev@logging.apache.org by ch...@apache.org on 2009/10/12 01:18:53 UTC

svn commit: r824196 - in /incubator/log4php/trunk/src: changes/changes.xml main/php/LoggerLoggingEvent.php test/php/renderers/LoggerRendererMapTest.php test/php/renderers/test4.properties

Author: chammers
Date: Sun Oct 11 23:18:53 2009
New Revision: 824196

URL: http://svn.apache.org/viewvc?rev=824196&view=rev
Log:
LOG4PHP-84 - undefined method in LoggerLoggingEvent when using LoggerRendererMap
* Added test case
* Added fix to LoggerLoggingEvent
* Renamed logger in the properties file as the test failed when using ant while it
  succeeded when calling phpunit on this test directly. Probably because phpunit
  safed some static properties of some of the Logger classes between severy test files.

Modified:
    incubator/log4php/trunk/src/changes/changes.xml
    incubator/log4php/trunk/src/main/php/LoggerLoggingEvent.php
    incubator/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php
    incubator/log4php/trunk/src/test/php/renderers/test4.properties

Modified: incubator/log4php/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/changes/changes.xml?rev=824196&r1=824195&r2=824196&view=diff
==============================================================================
--- incubator/log4php/trunk/src/changes/changes.xml (original)
+++ incubator/log4php/trunk/src/changes/changes.xml Sun Oct 11 23:18:53 2009
@@ -80,6 +80,7 @@
      	<action type="fix" issue="LOG4PHP-80" by="Christian Hammers">An exception is now thrown if an unknown property is set via config file</action>
 		<action type="fix" issue="LOG4PHP-81" by="Christian Hammers">Boolean values in .properties files are now correctly parsed</action>
 		<action type="fix" issue="LOG4PHP-82" by="Christian Hammers">Added more examples to the API docs</action>
+		<action type="fix" issue="LOG4PHP-84" by="Christian Hammers">Fixed call of undefined method when using RendererMap</action>
 		<action type="fix" issue="LOG4PHP-86" by="Christian Hammers">LoggerAppenderRollingFile should not fail if the file does not already exist</action>
 		<action type="fix" by="Christian Grobmeier">LoggerXmlConfigurator can now interpret threshold commands at appender level</action>
 		<action type="update" by="Knut Urdalen">Initial port to PHP 5</action>

Modified: incubator/log4php/trunk/src/main/php/LoggerLoggingEvent.php
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/LoggerLoggingEvent.php?rev=824196&r1=824195&r2=824196&view=diff
==============================================================================
--- incubator/log4php/trunk/src/main/php/LoggerLoggingEvent.php (original)
+++ incubator/log4php/trunk/src/main/php/LoggerLoggingEvent.php Sun Oct 11 23:18:53 2009
@@ -261,17 +261,13 @@
 			if(is_string($this->message)) {
 					$this->renderedMessage = $this->message;
 			} else {
-				if($this->logger !== null) {
-					$repository = $this->logger->getLoggerRepository();
-				} else {
-					$repository = Logger::getLoggerRepository();
-				}
-				if(method_exists($repository, 'getRendererMap')) {
-					$rendererMap = $repository->getRendererMap();
-					$this->renderedMessage= $rendererMap->findAndRender($this->message);
-				} else {
-					$this->renderedMessage = (string)$this->message;
-				}
+			    // $this->logger might be null or an instance of Logger or RootLogger
+			    // But in contrast to log4j, in log4php there is only have one LoggerHierarchy so there is
+			    // no need figure out which one is $this->logger part of.
+			    // TODO: Logger::getHierarchy() is marked @deprecated!
+				$repository = Logger::getHierarchy();
+				$rendererMap = $repository->getRendererMap();
+				$this->renderedMessage= $rendererMap->findAndRender($this->message);
 			}
 		}
 		return $this->renderedMessage;

Modified: incubator/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php?rev=824196&r1=824195&r2=824196&view=diff
==============================================================================
--- incubator/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php (original)
+++ incubator/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php Sun Oct 11 23:18:53 2009
@@ -49,7 +49,7 @@
         
 	public function testGetByObject() {
 		$fruit = new Fruit3();
-		Logger::configure('renderers/test4.properties');
+		Logger::configure(dirname(__FILE__).'/test4.properties');
 		Logger::initialize();
 		$hierarchy = Logger::getHierarchy();
 		
@@ -59,7 +59,7 @@
 	}
         
 	public function testGetByClassName() {
-		Logger::configure('renderers/test4.properties');
+		Logger::configure(dirname(__FILE__).'/test4.properties');
 		Logger::initialize();
 		$hierarchy = Logger::getHierarchy();
 		
@@ -67,4 +67,18 @@
 		$e = $map->getByClassName('Fruit3');
 		self::assertTrue($e instanceof FruitRenderer3);
 	}
+	
+	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();
+        ob_end_clean();
+
+        self::assertEquals("ERROR - test1,test2,test3\n", $v);
+	}
 }

Modified: incubator/log4php/trunk/src/test/php/renderers/test4.properties
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/renderers/test4.properties?rev=824196&r1=824195&r2=824196&view=diff
==============================================================================
--- incubator/log4php/trunk/src/test/php/renderers/test4.properties (original)
+++ incubator/log4php/trunk/src/test/php/renderers/test4.properties Sun Oct 11 23:18:53 2009
@@ -19,9 +19,9 @@
 log4php.appender.default.layout = LoggerLayoutSimple
 log4php.appender.default.threshold = WARN
 
-log4php.appender.blub = LoggerAppenderEcho
-log4php.appender.blub.layout = LoggerLayoutSimple
-log4php.appender.blub.threshold = INFO
+log4php.appender.blub2 = LoggerAppenderEcho
+log4php.appender.rendr2.layout = LoggerLayoutSimple
+log4php.appender.rendr2.threshold = INFO
 
 log4php.threshold = WARN
-log4php.rootLogger = WARN, default, blub
+log4php.rootLogger = WARN, default, rendr2