Author: grobmeier
Date: Mon Mar 22 06:08:09 2010
New Revision: 925964

URL: http://svn.apache.org/viewvc?rev=925964&view=rev
Log:
LOG4PHP-100: Added patch from Moritz Schmidt: Directly assign an array on 
Logger PHP configuration

Modified:
    incubator/log4php/trunk/src/changes/changes.xml
    incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorPhp.php
    
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorPhpTest.php

Modified: incubator/log4php/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/changes/changes.xml?rev=925964&r1=925963&r2=925964&view=diff
==============================================================================
--- incubator/log4php/trunk/src/changes/changes.xml (original)
+++ incubator/log4php/trunk/src/changes/changes.xml Mon Mar 22 06:08:09 2010
@@ -24,6 +24,7 @@
   </properties>
   <body>
        <release version="2.1" description="Stabilizing">
+               <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>
                <action type="fix" issue="LOG4PHP-96" by="Tommy 
Montgomery">Some of the tests don't pass under Windows</action>

Modified: 
incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorPhp.php
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorPhp.php?rev=925964&r1=925963&r2=925964&view=diff
==============================================================================
--- 
incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorPhp.php 
(original)
+++ 
incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorPhp.php 
Mon Mar 22 06:08:09 2010
@@ -21,8 +21,9 @@
 /**
  * LoggerConfiguratorPhp class
  *
- * This class allows configuration of log4php through an external file that 
- * deliver a PHP array in return.
+ * This class allows configuration of log4php through a PHP array or an 
external file that
+ * returns a PHP array. If you use the PHP array option, you can simply give 
an array instead
+ * of an URL parameter.
  *
  * An example for this configurator is:
  *
@@ -43,8 +44,11 @@ class LoggerConfiguratorPhp implements L
        }
        
        private function doConfigure($url, LoggerHierarchy $hierarchy) {
-               
-               $config = require $url;
+               if (!is_array($url)) {
+                       $config = require $url;
+               } else {
+                   $config = $url;
+               }
                
                // set threshold
                if(isset($config['threshold'])) {

Modified: 
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorPhpTest.php
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorPhpTest.php?rev=925964&r1=925963&r2=925964&view=diff
==============================================================================
--- 
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorPhpTest.php
 (original)
+++ 
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorPhpTest.php
 Mon Mar 22 06:08:09 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
@@ -24,26 +25,71 @@
  */
 
 class LoggerConfiguratorPhpTest extends PHPUnit_Framework_TestCase {
-        
-       protected function setUp() {
-               
-       }
-       
-       protected function tearDown() {
-               Logger::resetConfiguration();
-       }
-       
-       public function testConfigure() {
-               
Logger::configure(dirname(__FILE__).'/test1.php','LoggerConfiguratorPhp');
-               $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());
-               $logger = Logger::getLogger('tracer');
-               self::assertEquals(LoggerLevel::getLevelTrace(), 
$logger->getLevel());
-       }
-}
+
+    protected function setUp() {
+
+    }
+
+    protected function tearDown() {
+        Logger :: resetConfiguration();
+    }
+
+    public function testConfigure() {
+        Logger :: configure(dirname(__FILE__) . '/test1.php', 
'LoggerConfiguratorPhp');
+        $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());
+        $logger = Logger :: getLogger('tracer');
+        self :: assertEquals(LoggerLevel :: getLevelTrace(), 
$logger->getLevel());
+    }
+
+    public function testConfigureArray() {
+        Logger :: configure(array (
+            'threshold' => 'ALL',
+            'rootLogger' => array (
+                'level' => 'WARN',
+                'appenders' => array (
+                    'default'
+                ),
+            ),
+            'loggers' => array (
+                'mylogger' => array (
+                    'level' => 'INFO',
+                    'appenders' => array (
+                        'default'
+                    ),
+                ),
+                'tracer' => array (
+                    'level' => 'TRACE',
+                    'appenders' => array (
+                        'default'
+                    ),
+                ),
+            ),
+            'appenders' => array (
+                'default' => array (
+                    'class' => 'LoggerAppenderEcho',
+                    'layout' => array (
+                        'class' => 'LoggerLayoutSimple'
+                    ),
+                ),
+            ),
+            
+        ), 'LoggerConfiguratorPhp');
+        $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());
+        $logger = Logger :: getLogger('tracer');
+        self :: assertEquals(LoggerLevel :: getLevelTrace(), 
$logger->getLevel());
+    }
+}
\ No newline at end of file


Reply via email to