Author: grobmeier
Date: Wed Aug  5 06:13:03 2009
New Revision: 801073

URL: http://svn.apache.org/viewvc?rev=801073&view=rev
Log:
LOG4PHP-59: LoggerAppenderConsole is initialized wrong. Configurator needs to 
take care for activateOptions themselve. 

Modified:
    incubator/log4php/trunk/src/changes/changes.xml
    incubator/log4php/trunk/src/main/php/appenders/LoggerAppenderConsole.php
    
incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorBasic.php
    incubator/log4php/trunk/src/test/php/appenders/LoggerAppenderConsoleTest.php
    
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorBasicTest.php

Modified: incubator/log4php/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/changes/changes.xml?rev=801073&r1=801072&r2=801073&view=diff
==============================================================================
--- incubator/log4php/trunk/src/changes/changes.xml (original)
+++ incubator/log4php/trunk/src/changes/changes.xml Wed Aug  5 06:13:03 2009
@@ -60,6 +60,7 @@
                <action type="update" issue="LOG4PHP-52">Use of custom factorys 
is discouraged - clean up (Christian Grobmeier)</action>
                <action type="update" issue="LOG4PHP-53">Removed references 
were appropriate (Christian Grobmeier)</action>
                <action type="fix" issue="LOG4PHP-54">PHPDoc is wrong due to 
class movements - clean up (Christian Grobmeier)</action>
+               <action type="fix" issue="LOG4PHP-59">LoggerAppenderConsole is 
initialized wrong (Christian Grobmeier, Christian Hammers)</action>
                <action type="update" issue="LOG4PHP-60">Improved 
quickstart.apt (Christian Hammers)</action>
                <action type="update" issue="LOG4PHP-62">Does not print warning 
if ini file is corrupt (Christian Hammers)</action>
                <action type="update" issue="LOG4PHP-63">PDOAppender should 
throw LoggerException on database problems (Christian Hammers)</action>

Modified: 
incubator/log4php/trunk/src/main/php/appenders/LoggerAppenderConsole.php
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/appenders/LoggerAppenderConsole.php?rev=801073&r1=801072&r2=801073&view=diff
==============================================================================
--- incubator/log4php/trunk/src/main/php/appenders/LoggerAppenderConsole.php 
(original)
+++ incubator/log4php/trunk/src/main/php/appenders/LoggerAppenderConsole.php 
Wed Aug  5 06:13:03 2009
@@ -51,7 +51,7 @@
         * @var mixed the resource used to open stdout/stderr
         * @access private         
         */
-       protected $fp = false;
+       protected $fp = null;
 
        /**
         * Set console target.
@@ -68,25 +68,25 @@
 
        public function activateOptions() {
                $this->fp = fopen($this->target, 'w');
-               if($this->fp !== false && $this->layout !== null) {
+               if(is_resource($this->fp) && $this->layout !== null) {
                        fwrite($this->fp, $this->layout->getHeader());
                }
-               $this->closed = (bool)($this->fp === false);
+               $this->closed = (bool)is_resource($this->fp);
        }
        
        /**
         * @see LoggerAppender::close()
         */
        public function close() {
-               if ($this->fp && $this->layout !== null) {
+               if (is_resource($this->fp) && $this->layout !== null) {
                        fwrite($this->fp, $this->layout->getFooter());
-                                               fclose($this->fp);
+                       fclose($this->fp);
                }                
                $this->closed = true;
        }
 
        public function append($event) {
-               if ($this->fp && $this->layout !== null) {
+               if (is_resource($this->fp) && $this->layout !== null) {
                        fwrite($this->fp, $this->layout->format($event));
                } 
        }

Modified: 
incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorBasic.php
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorBasic.php?rev=801073&r1=801072&r2=801073&view=diff
==============================================================================
--- 
incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorBasic.php 
(original)
+++ 
incubator/log4php/trunk/src/main/php/configurators/LoggerConfiguratorBasic.php 
Wed Aug  5 06:13:03 2009
@@ -39,20 +39,7 @@
                $root = Logger::getRootLogger();
                $appender = new LoggerAppenderConsole('A1');
                $appender->setLayout( new LoggerLayoutTTCC() );
+               $appender->activateOptions();
                $root->addAppender($appender);
        }
-
-       /**
-        * Reset the default hierarchy to its default. 
-        * It is equivalent to
-        * <code>
-        * Logger::resetConfiguration();
-        * </code>
-        *
-        * @see LoggerHierarchy::resetConfiguration()
-        * @static
-        */
-       public static function resetConfiguration() {
-               Logger::resetConfiguration();
-       }
 }

Modified: 
incubator/log4php/trunk/src/test/php/appenders/LoggerAppenderConsoleTest.php
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/appenders/LoggerAppenderConsoleTest.php?rev=801073&r1=801072&r2=801073&view=diff
==============================================================================
--- 
incubator/log4php/trunk/src/test/php/appenders/LoggerAppenderConsoleTest.php 
(original)
+++ 
incubator/log4php/trunk/src/test/php/appenders/LoggerAppenderConsoleTest.php 
Wed Aug  5 06:13:03 2009
@@ -34,11 +34,18 @@
                                                                        "my 
message");
        
        $appender = new LoggerAppenderConsole("mylogger"); 
-               $appender->setTarget('STDOUT');
+       $appender->setTarget('STDOUT');
                $appender->setLayout($layout);
                $appender->activateOptions();
+               
+               ob_start();
                $appender->append($event);
+               $v = ob_get_contents();
+               ob_end_clean();
+               
                $appender->close();
+               
+               //echo $v;
     }
      
     public function testSimpleStdErrLogging() {

Modified: 
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorBasicTest.php
URL: 
http://svn.apache.org/viewvc/incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorBasicTest.php?rev=801073&r1=801072&r2=801073&view=diff
==============================================================================
--- 
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorBasicTest.php
 (original)
+++ 
incubator/log4php/trunk/src/test/php/configurators/LoggerConfiguratorBasicTest.php
 Wed Aug  5 06:13:03 2009
@@ -30,7 +30,7 @@
        }
         
        protected function tearDown() {
-               LoggerConfiguratorBasic::resetConfiguration();
+               Logger::resetConfiguration();
        }
         
        public function testConfigure() {
@@ -39,6 +39,19 @@
                self::assertType('LoggerAppenderConsole', $appender);
                $layout = $appender->getLayout();
                self::assertType('LoggerLayoutTTCC', $layout);
+               
+               $event = new LoggerLoggingEvent('LoggerAppenderConsoleTest', 
+                                                                       new 
Logger('mycategory'), 
+                                                                       
LoggerLevel::getLevelWarn(),
+                                                                       "my 
message");
+               $appender->setTarget('STDOUT');
+               $appender->activateOptions();
+               
+               ob_start();
+               $appender->append($event);
+               $v = ob_get_contents();
+               ob_end_clean();
+               $appender->close();
        }
 
        public function testResetConfiguration() {
@@ -51,7 +64,7 @@
                // As PHPUnit runs all tests in one run, there might be some 
loggers left over
                // from previous runs. ResetConfiguration() only clears the 
appenders, it does
                // not remove the categories!
-               LoggerConfiguratorBasic::resetConfiguration();
+               Logger::resetConfiguration();
                $hierarchy = LoggerHierarchy::singleton();
         foreach ($hierarchy->getCurrentLoggers() as $logger) {
             self::assertEquals(0, count($logger->getAllAppenders()));


Reply via email to