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 gr...@apache.org on 2009/08/31 08:38:24 UTC

svn commit: r809468 - in /incubator/log4php/trunk/src: main/php/ main/php/configurators/ main/php/renderers/ test/php/configurators/ test/php/renderers/

Author: grobmeier
Date: Mon Aug 31 06:38:24 2009
New Revision: 809468

URL: http://svn.apache.org/viewvc?rev=809468&view=rev
Log:
added renderer configuration test

Modified:
    incubator/log4php/trunk/src/main/php/LoggerHierarchy.php
    incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorIni.php
    incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorXml.php
    incubator/log4php/trunk/src/main/php/renderers/LoggerRendererMap.php
    incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorIniTest.php
    incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorXmlTest.php
    incubator/log4php/trunk/src/test/php/configurators/test1.xml
    incubator/log4php/trunk/src/test/php/configurators/test4.properties
    incubator/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php

Modified: incubator/log4php/trunk/src/main/php/LoggerHierarchy.php
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/LoggerHierarchy.php?rev=809468&r1=809467&r2=809468&view=diff
==============================================================================
--- incubator/log4php/trunk/src/main/php/LoggerHierarchy.php (original)
+++ incubator/log4php/trunk/src/main/php/LoggerHierarchy.php Mon Aug 31 06:38:24 2009
@@ -74,22 +74,11 @@
 	 */
 	public function __construct(LoggerRoot $root) {
 		$this->root = $root;
-		// TODO: isn't necessary, access via singleton?'
-//		$this->root->setHierarchy($this);
 		$this->setThreshold(LoggerLevel::getLevelAll());
 		$this->rendererMap = new LoggerRendererMap();
 	}
 	 
 	/**
-	 * Add an object renderer for a specific class.
-	 * @param string $classToRender
-	 * @param LoggerObjectRenderer $or
-	 */
-	public function addRenderer($classToRender, $or) {
-		$this->rendererMap->put($classToRender, $or);
-	} 
-	
-	/**
 	 * This call will clear all logger definitions from the internal hashtable.
 	 */
 	public function clear() {
@@ -218,16 +207,6 @@
 	}
 	
 	/**
-	 * Used by subclasses to add a renderer to the hierarchy passed as parameter.
-	 * @param string $renderedClass a LoggerRenderer class name
-	 * @param LoggerRenderer $renderer
-	 *
-	 */
-	public function setRenderer($renderedClass, $renderer) {
-		$this->rendererMap->put($renderedClass, $renderer);
-	}
-	
-	/**
 	 * set a new threshold level
 	 *
 	 * @param LoggerLevel $l

Modified: incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorIni.php
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorIni.php?rev=809468&r1=809467&r2=809468&view=diff
==============================================================================
--- incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorIni.php (original)
+++ incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorIni.php Mon Aug 31 06:38:24 2009
@@ -351,9 +351,7 @@
 			} else if(strpos($key, self::RENDERER_PREFIX) === 0) {
 				$renderedClass = substr($key, strlen(self::RENDERER_PREFIX));
 				$renderingClass = $value;
-				if(method_exists($hierarchy, 'addrenderer')) { // ?
-					LoggerRendererMap::addRenderer($hierarchy, $renderedClass, $renderingClass);
-				}
+				$hierarchy->getRendererMap()->addRenderer($renderedClass, $renderingClass);
 			}
 		}
 	}

Modified: incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorXml.php
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorXml.php?rev=809468&r1=809467&r2=809468&view=diff
==============================================================================
--- incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorXml.php (original)
+++ incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorXml.php Mon Aug 31 06:38:24 2009
@@ -361,12 +361,7 @@
                 $renderingClass  = $this->subst(@$attribs['RENDERINGCLASS']);
         
                 if (!empty($renderedClass) and !empty($renderingClass)) {
-                    $renderer = LoggerReflectionUtils::createObject($renderingClass);
-                    if ($renderer === null) {
-                        // LoggerDOMConfigurator::tagOpen() RENDERER cannot instantiate '$renderingClass'
-                    } else { 
-                        $this->repository->setRenderer($renderedClass, $renderer);
-                    }
+                    $this->repository->getRendererMap()->addRenderer($renderedClass, $renderingClass);
                 }
                 break;
             

Modified: incubator/log4php/trunk/src/main/php/renderers/LoggerRendererMap.php
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/renderers/LoggerRendererMap.php?rev=809468&r1=809467&r2=809468&view=diff
==============================================================================
--- incubator/log4php/trunk/src/main/php/renderers/LoggerRendererMap.php (original)
+++ incubator/log4php/trunk/src/main/php/renderers/LoggerRendererMap.php Mon Aug 31 06:38:24 2009
@@ -54,12 +54,12 @@
 	 * @param string $renderingClassName
 	 * @static
 	 */
-	public static function addRenderer($repository, $renderedClassName, $renderingClassName) {
+	public function addRenderer($renderedClassName, $renderingClassName) {
 		$renderer = LoggerReflectionUtils::createObject($renderingClassName);
 		if($renderer == null) {
 			return;
 		} else {
-			$repository->setRenderer($renderedClassName, $renderer);
+			$this->put($renderedClassName, $renderer);
 		}
 	}
 
@@ -142,7 +142,7 @@
 	 * @param string $class
 	 * @param LoggerRendererObject $or
 	 */
-	public function put($class, $or) {
+	private function put($class, $or) {
 		$this->map[strtolower($class)] = $or;
 	}
 	

Modified: incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorIniTest.php
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorIniTest.php?rev=809468&r1=809467&r2=809468&view=diff
==============================================================================
--- incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorIniTest.php (original)
+++ incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorIniTest.php Mon Aug 31 06:38:24 2009
@@ -23,6 +23,18 @@
  * @link       http://logging.apache.org/log4php
  */
 
+class Fruit {
+    public $test1 = 'test1';
+    public $test2 = 'test2';
+    public $test3 = 'test3';
+}
+
+class FruitRenderer extends LoggerRendererObject {
+    public function doRender($o) {
+		return $o->test1.','.$o->test2.','.$o->test3;
+	}
+}
+
 class LoggerConfiguratorIniTest extends PHPUnit_Framework_TestCase {
         
 	protected function setUp() {
@@ -113,4 +125,13 @@
 		$e = LoggerLevel::getLevelWarn();
 		self::assertEquals($e,$threshold);
 	}
+	
+	public function testRenderer() {
+		Logger::configure('configurators/test4.properties');
+		Logger::initialize();
+		$hierarchy = Logger::getHierarchy();
+		$map = $hierarchy->getRendererMap();
+		$clazz = $map->getByClassName('Fruit');
+		self::assertTrue($clazz instanceof FruitRenderer);
+	}
 }

Modified: incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorXmlTest.php
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorXmlTest.php?rev=809468&r1=809467&r2=809468&view=diff
==============================================================================
--- incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorXmlTest.php (original)
+++ incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorXmlTest.php Mon Aug 31 06:38:24 2009
@@ -22,6 +22,17 @@
  * @version    SVN: $Id$
  * @link       http://logging.apache.org/log4php
  */
+class Fruit2 {
+    public $test1 = 'test1';
+    public $test2 = 'test2';
+    public $test3 = 'test3';
+}
+
+class FruitRenderer2 extends LoggerRendererObject {
+    public function doRender($o) {
+		return $o->test1.','.$o->test2.','.$o->test3;
+	}
+}
 
 class LoggerConfiguratorXmlTest extends PHPUnit_Framework_TestCase {
         
@@ -78,5 +89,10 @@
 		self::assertTrue($threshold instanceof LoggerLevel);
 		$e = LoggerLevel::getLevelWarn();
 		self::assertEquals($e,$threshold);
+		
+		$hierarchy = Logger::getHierarchy();
+		$map = $hierarchy->getRendererMap();
+		$clazz = $map->getByClassName('Fruit2');
+		self::assertTrue($clazz instanceof FruitRenderer2);
 	}
 }

Modified: incubator/log4php/trunk/src/test/php/configurators/test1.xml
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/configurators/test1.xml?rev=809468&r1=809467&r2=809468&view=diff
==============================================================================
--- incubator/log4php/trunk/src/test/php/configurators/test1.xml (original)
+++ incubator/log4php/trunk/src/test/php/configurators/test1.xml Mon Aug 31 06:38:24 2009
@@ -17,6 +17,7 @@
 
 -->
 <log4php:configuration xmlns:log4php="http://logging.apache.org/log4php/" threshold="WARN">
+	<renderer renderedClass="Fruit2" renderingClass="FruitRenderer2" />
     <appender threshold="WARN" name="default" class="LoggerAppenderEcho">
         <layout class="LoggerLayoutSimple"/>
     </appender>

Modified: incubator/log4php/trunk/src/test/php/configurators/test4.properties
URL: http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/configurators/test4.properties?rev=809468&r1=809467&r2=809468&view=diff
==============================================================================
--- incubator/log4php/trunk/src/test/php/configurators/test4.properties (original)
+++ incubator/log4php/trunk/src/test/php/configurators/test4.properties Mon Aug 31 06:38:24 2009
@@ -13,6 +13,8 @@
 ; See the License for the specific language governing permissions and
 ; limitations under the License.
 ;
+log4php.renderer.Fruit=FruitRenderer
+
 log4php.appender.default = LoggerAppenderEcho
 log4php.appender.default.layout = LoggerLayoutSimple
 log4php.appender.default.threshold = WARN

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=809468&r1=809467&r2=809468&view=diff
==============================================================================
--- incubator/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php (original)
+++ incubator/log4php/trunk/src/test/php/renderers/LoggerRendererMapTest.php Mon Aug 31 06:38:24 2009
@@ -28,7 +28,7 @@
 	public function testAddRenderer() {
 		$hierarchy = Logger::getHierarchy();
 		//print_r($hierarchy);
-		LoggerRendererMap::addRenderer($hierarchy, 'string', 'LoggerRendererDefault');
+		$hierarchy->getRendererMap()->addRenderer('string', 'LoggerRendererDefault');
 		//print_r($hierarchy);
 		self::markTestIncomplete();
 	}