Author: grobmeier
Date: Mon Mar 22 06:20:32 2010
New Revision: 925969

URL: http://svn.apache.org/viewvc?rev=925969&view=rev
Log:
LOG4PHP-103: Added patch from Moritz Schmidt: Exception when using more than 
one LoggerAppenderFile (slightly modified)

Added:
    incubator/log4php/trunk/src/test/php/configurators/test5.properties
Modified:
    incubator/log4php/trunk/src/changes/changes.xml
    incubator/log4php/trunk/src/main/php/LoggerReflectionUtils.php
    
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorIniTest.php

Modified: incubator/log4php/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/changes/changes.xml?rev=925969&r1=925968&r2=925969&view=diff
==============================================================================
--- incubator/log4php/trunk/src/changes/changes.xml (original)
+++ incubator/log4php/trunk/src/changes/changes.xml Mon Mar 22 06:20:32 2010
@@ -24,6 +24,7 @@
   </properties>
   <body>
        <release version="2.1" description="Stabilizing">
+               <action type="update" issue="LOG4PHP-103" by="Moritz 
Schmidt">Exception when using more than one LoggerAppenderFile</action>
                <action type="update" issue="LOG4PHP-100" by="Moritz 
Schmidt">Directly assign an array on Logger PHP configuration</action>
                <action type="fix" issue="LOG4PHP-91">LoginOptionConverter.php 
(used wrong constant name)</action>
                <action type="update" issue="LOG4PHP-95" by="Ivan Habunek, 
Christian Grobmeier">Add trace level to Log4PHP</action>

Modified: incubator/log4php/trunk/src/main/php/LoggerReflectionUtils.php
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/LoggerReflectionUtils.php?rev=925969&r1=925968&r2=925969&view=diff
==============================================================================
--- incubator/log4php/trunk/src/main/php/LoggerReflectionUtils.php (original)
+++ incubator/log4php/trunk/src/main/php/LoggerReflectionUtils.php Mon Mar 22 
06:20:32 2010
@@ -69,6 +69,7 @@ class LoggerReflectionUtils {
         // TODO: check, if this is really useful
        public function setProperties($properties, $prefix) {
                $len = strlen($prefix);
+               reset($properties);
                while(list($key,) = each($properties)) {
                        if(strpos($key, $prefix) === 0) {
                                if(strpos($key, '.', ($len + 1)) > 0) {

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=925969&r1=925968&r2=925969&view=diff
==============================================================================
--- 
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorIniTest.php
 (original)
+++ 
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorIniTest.php
 Mon Mar 22 06:20:32 2010
@@ -1,4 +1,5 @@
 <?php
+
 /**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -31,111 +32,125 @@ class Fruit {
 
 class FruitRenderer implements LoggerRendererObject {
     public function render($o) {
-               return $o->test1.','.$o->test2.','.$o->test3;
-       }
+        return $o->test1 . ',' . $o->test2 . ',' . $o->test3;
+    }
 }
 
 class LoggerConfiguratorIniTest extends PHPUnit_Framework_TestCase {
-        
-       protected function setUp() {
-               
-       }
-       
-       protected function tearDown() {
-               Logger::resetConfiguration();
-       }
-        
-       public function testConfigure() {
-               Logger::configure('configurators/test1.properties');
-               $root = Logger::getRootLogger();
-               self::assertEquals(LoggerLevel::getLevelWarn(), 
$root->getLevel());
-               $appender = $root->getAppender("default");
-               self::assertTrue($appender instanceof LoggerAppenderEcho);
-               $layout = $appender->getLayout();
-               self::assertTrue($layout instanceof LoggerLayoutSimple);
-               
-               $logger = Logger::getLogger('mylogger');
-               self::assertEquals(LoggerLevel::getLevelInfo(), 
$logger->getLevel());
-               self::assertFalse($logger->getAdditivity());
-               
-               $logger3 = Logger::getLogger('tracer');
-               self::assertEquals(LoggerLevel::getLevelTrace(), 
$logger3->getLevel());
-               self::assertFalse($logger3->getAdditivity());
-               
-               $logger2 = Logger::getLogger('mylogger');
-               $logger2->setAdditivity(true);
-               self::assertTrue($logger2->getAdditivity());
-               self::assertTrue($logger->getAdditivity());
-       }
-       
-       public function testConfigureWithRootCategory() {
-               Logger::configure('configurators/test3.properties');
-               $root = Logger::getRootLogger();
-               self::assertEquals(LoggerLevel::getLevelWarn(), 
$root->getLevel());
-               $appender = $root->getAppender("default");
-               self::assertTrue($appender instanceof LoggerAppenderEcho);
-               $layout = $appender->getLayout();
-               self::assertTrue($layout instanceof LoggerLayoutSimple);
-       }
-       
-       public function testConfigureWithoutIniFile() {
-           $catchedException = null;
-           try {
-              Logger::configure(null,'LoggerConfiguratorIni');
-              Logger::initialize();
-              self::assertTrue(false);
-           } catch (LoggerException $e) {
-               $catchedException = $e;
-           }
-               self::assertNotNull($catchedException);
-       }
-       
-       public function testConfigureWithEmptyIniFile() {
-               $catchedException = null;
-           try {
-              Logger::configure('configurators/test2.properties');
-              Logger::initialize();
-              self::assertTrue(false);
-           } catch (LoggerException $e) {
-               $catchedException = $e;
-           }
-               self::assertNotNull($catchedException);
-       }
-       
-       public function testThreshold() {
-               Logger::configure('configurators/test4.properties');
-               $root = Logger::getRootLogger();
-               self::assertEquals(LoggerLevel::getLevelWarn(), 
$root->getLevel());
-               $appender = $root->getAppender("default");
-               self::assertTrue($appender instanceof LoggerAppenderEcho);
-               $layout = $appender->getLayout();
-               self::assertTrue($layout instanceof LoggerLayoutSimple);
-               $threshold = $appender->getThreshold();
-               self::assertTrue($threshold instanceof LoggerLevel);
-               $e = LoggerLevel::getLevelWarn();
-               self::assertEquals($e,$threshold);
-               
-               $appender = $root->getAppender("blub");
-               self::assertTrue($appender instanceof LoggerAppenderEcho);
-               $layout = $appender->getLayout();
-               self::assertTrue($layout instanceof LoggerLayoutSimple);
-               $threshold = $appender->getThreshold();
-               self::assertTrue($threshold instanceof LoggerLevel);
-               $e = LoggerLevel::getLevelInfo();
-               self::assertEquals($e,$threshold);
-               
-               $threshold = Logger::getHierarchy()->getThreshold();
-               self::assertTrue($threshold instanceof LoggerLevel);
-               $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);
-       }
-}
+
+    protected function setUp() {
+
+    }
+
+    protected function tearDown() {
+        Logger :: resetConfiguration();
+    }
+
+    public function testConfigure() {
+        Logger :: configure('configurators/test1.properties');
+        $root = Logger :: getRootLogger();
+        self :: assertEquals(LoggerLevel :: getLevelWarn(), $root->getLevel());
+        $appender = $root->getAppender("default");
+        self :: assertTrue($appender instanceof LoggerAppenderEcho);
+        $layout = $appender->getLayout();
+        self :: assertTrue($layout instanceof LoggerLayoutSimple);
+
+        $logger = Logger :: getLogger('mylogger');
+        self :: assertEquals(LoggerLevel :: getLevelInfo(), 
$logger->getLevel());
+        self :: assertFalse($logger->getAdditivity());
+
+        $logger3 = Logger :: getLogger('tracer');
+        self :: assertEquals(LoggerLevel :: getLevelTrace(), 
$logger3->getLevel());
+        self :: assertFalse($logger3->getAdditivity());
+
+        $logger2 = Logger :: getLogger('mylogger');
+        $logger2->setAdditivity(true);
+        self :: assertTrue($logger2->getAdditivity());
+        self :: assertTrue($logger->getAdditivity());
+    }
+
+    public function testConfigureWithRootCategory() {
+        Logger :: configure('configurators/test3.properties');
+        $root = Logger :: getRootLogger();
+        self :: assertEquals(LoggerLevel :: getLevelWarn(), $root->getLevel());
+        $appender = $root->getAppender("default");
+        self :: assertTrue($appender instanceof LoggerAppenderEcho);
+        $layout = $appender->getLayout();
+        self :: assertTrue($layout instanceof LoggerLayoutSimple);
+    }
+
+    public function testConfigureWithoutIniFile() {
+        $catchedException = null;
+        try {
+            Logger :: configure(null, 'LoggerConfiguratorIni');
+            Logger :: initialize();
+            self :: assertTrue(false);
+        } catch (LoggerException $e) {
+            $catchedException = $e;
+        }
+        self :: assertNotNull($catchedException);
+    }
+
+    public function testConfigureWithEmptyIniFile() {
+        $catchedException = null;
+        try {
+            Logger :: configure('configurators/test2.properties');
+            Logger :: initialize();
+            self :: assertTrue(false);
+        } catch (LoggerException $e) {
+            $catchedException = $e;
+        }
+        self :: assertNotNull($catchedException);
+    }
+
+    public function testThreshold() {
+        Logger :: configure('configurators/test4.properties');
+        $root = Logger :: getRootLogger();
+        self :: assertEquals(LoggerLevel :: getLevelWarn(), $root->getLevel());
+        $appender = $root->getAppender("default");
+        self :: assertTrue($appender instanceof LoggerAppenderEcho);
+        $layout = $appender->getLayout();
+        self :: assertTrue($layout instanceof LoggerLayoutSimple);
+        $threshold = $appender->getThreshold();
+        self :: assertTrue($threshold instanceof LoggerLevel);
+        $e = LoggerLevel :: getLevelWarn();
+        self :: assertEquals($e, $threshold);
+
+        $appender = $root->getAppender("blub");
+        self :: assertTrue($appender instanceof LoggerAppenderEcho);
+        $layout = $appender->getLayout();
+        self :: assertTrue($layout instanceof LoggerLayoutSimple);
+        $threshold = $appender->getThreshold();
+        self :: assertTrue($threshold instanceof LoggerLevel);
+        $e = LoggerLevel :: getLevelInfo();
+        self :: assertEquals($e, $threshold);
+
+        $threshold = Logger :: getHierarchy()->getThreshold();
+        self :: assertTrue($threshold instanceof LoggerLevel);
+        $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);
+    }
+
+    public function testSeveralLoggers() {
+        Logger :: clear();
+        Logger :: configure('configurators/test5.properties');
+        $l = Logger :: getLogger('test50');
+        $l->warn('muh');
+        $this->assertTrue($l->getAppender('test50') instanceof 
LoggerAppenderFile);
+        $this->assertTrue($l->getAppender('test50')->getLayout() instanceof 
LoggerLayoutSimple);
+
+        $l = Logger :: getLogger('test51');
+        $l->warn('mŠh');
+        $this->assertTrue($l->getAppender('test51') instanceof 
LoggerAppenderFile);
+        $this->assertTrue($l->getAppender('test51')->getLayout() instanceof 
LoggerLayoutTTCC);
+    }
+}
\ No newline at end of file

Added: incubator/log4php/trunk/src/test/php/configurators/test5.properties
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/configurators/test5.properties?rev=925969&view=auto
==============================================================================
--- incubator/log4php/trunk/src/test/php/configurators/test5.properties (added)
+++ incubator/log4php/trunk/src/test/php/configurators/test5.properties Mon Mar 
22 06:20:32 2010
@@ -0,0 +1,27 @@
+; Licensed to the Apache Software Foundation (ASF) under one or more
+; contributor license agreements.  See the NOTICE file distributed with
+; this work for additional information regarding copyright ownership.
+; The ASF licenses this file to You under the Apache License, Version 2.0
+; (the "License"); you may not use this file except in compliance with
+; the License.  You may obtain a copy of the License at
+;
+;      http://www.apache.org/licenses/LICENSE-2.0
+;
+; Unless required by applicable law or agreed to in writing, software
+; distributed under the License is distributed on an "AS IS" BASIS,
+; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+; See the License for the specific language governing permissions and
+; limitations under the License.
+;
+
+log4php.appender.test51 = LoggerAppenderFile
+log4php.appender.test51.file = /tmp/51.log
+log4php.appender.test51.layout = LoggerLayoutTTCC
+
+log4php.appender.test50 = LoggerAppenderFile
+log4php.appender.test50.file = /tmp/50.log
+log4php.appender.test50.layout = LoggerLayoutSimple
+
+
+log4php.logger.test50 = DEBUG, test50
+log4php.logger.test51 = DEBUG, test51
\ No newline at end of file


Reply via email to