          );
          
          // Has an appender?
-Index: skeleton/util/log/LogCategory.class.php
-===================================================================
---- skeleton/util/log/LogCategory.class.php	(revision 13884)
-+++ skeleton/util/log/LogCategory.class.php	(working copy)
-@@ -4,14 +4,8 @@
-  * $Id$
-  */
- 
--  uses('util.log.LogLevel');
-+  uses('util.log.LogLevel', 'util.log.LoggingEvent', 'util.log.DefaultLayout');
- 
--  define('LOGGER_FLAG_INFO',    0x0001);
--  define('LOGGER_FLAG_WARN',    0x0002);
--  define('LOGGER_FLAG_ERROR',   0x0004);
--  define('LOGGER_FLAG_DEBUG',   0x0008);
--  define('LOGGER_FLAG_ALL',     LOGGER_FLAG_INFO | LOGGER_FLAG_WARN | LOGGER_FLAG_ERROR | LOGGER_FLAG_DEBUG);
--
-   /**
-    * The log category is the interface to be used. All logging information
-    * is sent to a log category via one of the info, warn, error, debug 
-@@ -40,36 +34,26 @@
-    * @purpose  Base class
-    */
-   class LogCategory extends Object {
--    public 
--      $_appenders= array(),
--      $_indicators= array(
--        LogLevel::INFO        => 'info',
--        LogLevel::WARN        => 'warn',
--        LogLevel::ERROR       => 'error',
--        LogLevel::DEBUG       => 'debug'
--      );
-+    protected static $DEFAULT_LAYOUT= NULL;
-+    protected $_appenders= array();
-+
-+    public $flags= 0;
-+    public $identifier= '';
-       
--    public
--      $flags,
--      $identifier,
--      $dateformat,
--      $format;
-+    static function __static() {
-+      self::$DEFAULT_LAYOUT= new DefaultLayout();
-+    }
- 
-     /**
-      * Constructor
-      *
-      * @param   string identifier
--     * @param   string format 
--     * @param   string dateformat
--     * @param   int flags
-+     * @param   int flags (defaults to all)
-      */
--    public function __construct($identifier, $format, $dateformat, $flags= LogLevel::ALL) {
--      $this->identifier= $identifier;
--      $this->format= $format;
--      $this->dateformat= $dateformat;
-+    public function __construct($identifier, $flags= LogLevel::ALL) {
-       $this->flags= $flags;
-+      $this->identifier= $identifier;
-       $this->_appenders= array();
--      
-     }
- 
-     /**
-@@ -92,28 +76,15 @@
-     }
-     
-     /**
--     * Private helper function
-+     * Calls all appenders
-      *
-      */
--    public function callAppenders() {
--      $args= func_get_args();
--      $flag= $args[0];
--      if (!($this->flags & $flag)) return;
--      
--      $args[0]= sprintf(
--        $this->format,
--        date($this->dateformat),
--        $this->identifier,
--        $this->_indicators[$flag]
--      );
--      
-+    protected function callAppenders($event) {
-+      $level= $event->getLevel();
-       foreach (array_keys($this->_appenders) as $appflag) {
--        if (!($flag & $appflag)) continue;
--        foreach (array_keys($this->_appenders[$appflag]) as $idx) {
--          call_user_func_array(
--            array($this->_appenders[$appflag][$idx], 'append'),
--            $args
--          );
-+        if (!($level & $appflag)) continue;
-+        foreach ($this->_appenders[$appflag] as $appender) {
-+          $appender->append($event);
-         }
-       }
-     }
-@@ -133,8 +104,8 @@
-      */
-     public function finalize() {
-       foreach ($this->_appenders as $flags => $appenders) {
--        foreach (array_keys($appenders) as $idx) {
--          $appenders[$idx]->finalize();
-+        foreach ($this->_appenders[$appflag] as $appender) {
-+          $appender->finalize();
-         }
-       }
-     }
-@@ -150,6 +121,7 @@
-      */
-     public function addAppender($appender, $flag= LogLevel::ALL) {
-       $this->_appenders[$flag][]= $appender;
-+      $appender->getLayout() || $appender->setLayout(self::$DEFAULT_LAYOUT);
-       return $appender;
-     }
- 
-@@ -165,6 +137,7 @@
-      */
-     public function withAppender($appender, $flag= LogLevel::ALL) {
-       $this->_appenders[$flag][]= $appender;
-+      $appender->getLayout() || $appender->setLayout(self::$DEFAULT_LAYOUT);
-       return $this;
-     }
-     
-@@ -211,9 +184,9 @@
-      * @param   mixed* args
-      */
-     public function info() {
-+      if (!($this->flags & LogLevel::INFO)) return;
-       $args= func_get_args();
--      array_unshift($args, LogLevel::INFO);
--      call_user_func_array(array($this, 'callAppenders'), $args);
-+      $this->callAppenders(new LoggingEvent($this, time(), getmypid(), LogLevel::INFO, $args));
-     }
- 
-     /**
-@@ -228,8 +201,9 @@
-      * @param   mixed* args
-      */
-     public function infof() {
-+      if (!($this->flags & LogLevel::INFO)) return;
-       $args= func_get_args();
--      $this->callAppenders(LogLevel::INFO, vsprintf($args[0], array_slice($args, 1)));
-+      $this->callAppenders(new LoggingEvent($this, time(), getmypid(), LogLevel::INFO, array(vsprintf($args[0], array_slice($args, 1)))));
-     }
- 
-     /**
-@@ -238,9 +212,9 @@
-      * @param   mixed* args
-      */
-     public function warn() {
-+      if (!($this->flags & LogLevel::WARN)) return;
-       $args= func_get_args();
--      array_unshift($args, LogLevel::WARN);
--      call_user_func_array(array($this, 'callAppenders'), $args);
-+      $this->callAppenders(new LoggingEvent($this, time(), getmypid(), LogLevel::WARN, $args));
-     }
- 
-     /**
-@@ -250,8 +224,9 @@
-      * @param   mixed* args
-      */
-     public function warnf() {
-+      if (!($this->flags & LogLevel::WARN)) return;
-       $args= func_get_args();
--      $this->callAppenders(LogLevel::WARN, vsprintf($args[0], array_slice($args, 1)));
-+      $this->callAppenders(new LoggingEvent($this, time(), getmypid(), LogLevel::WARN, array(vsprintf($args[0], array_slice($args, 1)))));
-     }
- 
-     /**
-@@ -260,9 +235,9 @@
-      * @param   mixed* args
-      */
-     public function error() {
-+      if (!($this->flags & LogLevel::ERROR)) return;
-       $args= func_get_args();
--      array_unshift($args, LogLevel::ERROR);
--      call_user_func_array(array($this, 'callAppenders'), $args);
-+      $this->callAppenders(new LoggingEvent($this, time(), getmypid(), LogLevel::ERROR, $args));
-     }
- 
-     /**
-@@ -272,8 +247,9 @@
-      * @param   mixed* args
-      */
-     public function errorf() {
-+      if (!($this->flags & LogLevel::ERROR)) return;
-       $args= func_get_args();
--      $this->callAppenders(LogLevel::ERROR, vsprintf($args[0], array_slice($args, 1)));
-+      $this->callAppenders(new LoggingEvent($this, time(), getmypid(), LogLevel::ERROR, array(vsprintf($args[0], array_slice($args, 1)))));
-     }
- 
-     /**
-@@ -282,9 +258,9 @@
-      * @param   mixed* args
-      */
-     public function debug() {
-+      if (!($this->flags & LogLevel::DEBUG)) return;
-       $args= func_get_args();
--      array_unshift($args, LogLevel::DEBUG);
--      call_user_func_array(array($this, 'callAppenders'), $args);
-+      $this->callAppenders(new LoggingEvent($this, time(), getmypid(), LogLevel::DEBUG, $args));
-     }
-  
-     /**
-@@ -294,8 +270,9 @@
-      * @param   mixed* args
-      */
-     public function debugf() {
-+      if (!($this->flags & LogLevel::DEBUG)) return;
-       $args= func_get_args();
--      $this->callAppenders(LogLevel::DEBUG, vsprintf($args[0], array_slice($args, 1)));
-+      $this->callAppenders(new LoggingEvent($this, time(), getmypid(), LogLevel::DEBUG, array(vsprintf($args[0], array_slice($args, 1)))));
-     }
-    
-     /**
-@@ -303,7 +280,20 @@
-      *
-      */
-     public function mark() {
--      $this->callAppenders(LogLevel::INFO, str_repeat('-', 72));
-+      $this->callAppenders(new LoggingEvent($this, time(), getmypid(), LogLevel::INFO, array(str_repeat('-', 72))));
-     }
-+
-+    /**
-+     * Returns whether another object is equal to this
-+     *
-+     * @param   lang.Generic cmp
-+     * @return  bool
-+     */
-+    public function equals($cmp) {
-+      return (
-+        $cmp instanceof self &&
-+        $cmp->flags === $this->flags
-+      );
-+    }
-   }
- ?>
-Index: skeleton/util/log/LogAppender.class.php
-===================================================================
---- skeleton/util/log/LogAppender.class.php	(revision 13884)
-+++ skeleton/util/log/LogAppender.class.php	(working copy)
-@@ -11,29 +11,49 @@
-    * @purpose  Base class
-    */
-   abstract class LogAppender extends Object {
-+    protected $layout= NULL;
- 
-     /**
-+     * Sets layout
-+     *
-+     * @param   util.log.Layout layout
-+     */
-+    public function setLayout(utillogLayout $layout) {
-+      $this->layout= $layout;
-+    }
-+    
-+    /**
-+     * Sets layout and returns this appender
-+     *
-+     * @param   util.log.Layout layout
-+     * @return  util.log.LogAppender
-+     */
-+    public function withLayout(utillogLayout $layout) {
-+      $this->layout= $layout;
-+      return $this;
-+    }
-+
-+    /**
-+     * Gets layout
-+     *
-+     * @return  util.log.Layout
-+     */
-+    public function getLayout() {
-+      return $this->layout;
-+    }
-+
-+    /**
-      * Append data
-      *
--     * @param   mixed* args
-+     * @param   util.log.LoggingEvent event
-      */ 
--    public abstract function append();
-- 
-+    public abstract function append(LoggingEvent $event);
-+    
-     /**
-      * Finalize this appender. This method is called when the logger
-      * is shut down. Does nothing in this default implementation.
-      *
-      */   
-     public function finalize() { }
--    
--    /**
--     * Retrieve a readable representation of a variable
--     *
--     * @param   mixed var
--     * @return  string
--     */
--    protected function varSource($var) {
--      return is_string($var) ? $var : xp::stringOf($var);
--    }
-   }
- ?>
 Index: skeleton/util/log/ConsoleAppender.class.php
 ===================================================================
 --- skeleton/util/log/ConsoleAppender.class.php	(revision 13884)

Index: skeleton/util/log/ColoredConsoleAppender.class.php
===================================================================
--- skeleton/util/log/ColoredConsoleAppender.class.php	(revision 13884)

     }
     
     /**
Index: ports/classes/net/xp_framework/unittest/logging/LogAppenderTest.class.php
===================================================================
--- ports/classes/net/xp_framework/unittest/logging/LogAppenderTest.class.php	(revision 0)
+++ ports/classes/net/xp_framework/unittest/logging/LogAppenderTest.class.php	(revision 0)
@@ -0,0 +1,97 @@
+<?php
+/* This class is part of the XP framework
+ *
+ * $Id$ 
+ */
+
+  uses(
+    'unittest.TestCase',
+    'util.log.LogAppender',
+    'util.log.LogCategory',
+    'util.log.PatternLayout',
+    'util.collections.Vector'
+  );
+
+  /**
+   * TestCase
+   *
+   * @see      reference
+   * @purpose  purpose
+   */
+  class LogAppenderTest extends TestCase {
+    protected $fixture= NULL;
+    protected $events= NULL;
+  
+    /**
+     * Sets up test case
+     *
+     */
+    public function setUp() {
+      $this->events= create('new Vector<String>()');
+      $appender= newinstance('util.log.LogAppender', array($this->events), '{
+        private $events= NULL;
+
+        public function __construct($events) {
+          $this->events= $events;
+        }
+
+        public function append(LoggingEvent $event) {
+          $this->events[]= new String($this->layout->format($event));
+        }
+      }');
+      $this->fixture= create(new LogCategory('default'))
+        ->withAppender($appender->withLayout(new PatternLayout('[%l] %m')))
+      ;
+    }
+    
+    /**
+     * Test
+     *
+     */
+    #[@test]
+    public function info() {
+      $this->fixture->info('Hello');
+      $this->assertEquals(new String('[info] Hello'), $this->events[0]);
+    }
+
+    /**
+     * Test
+     *
+     */
+    #[@test]
+    public function infoWithMultipleArguments() {
+      $this->fixture->info('Hello', 'World');
+      $this->assertEquals(new String('[info] Hello World'), $this->events[0]);
+    }
+
+    /**
+     * Test
+     *
+     */
+    #[@test]
+    public function warn() {
+      $this->fixture->warn('Hello');
+      $this->assertEquals(new String('[warn] Hello'), $this->events[0]);
+    }
+
+    /**
+     * Test
+     *
+     */
+    #[@test]
+    public function debug() {
+      $this->fixture->debug('Hello');
+      $this->assertEquals(new String('[debug] Hello'), $this->events[0]);
+    }
+
+    /**
+     * Test
+     *
+     */
+    #[@test]
+    public function error() {
+      $this->fixture->error('Hello');
+      $this->assertEquals(new String('[error] Hello'), $this->events[0]);
+    }
+  }
+?>

Property changes on: ports/classes/net/xp_framework/unittest/logging/LogAppenderTest.class.php
___________________________________________________________________
Added: svn:keywords
   + Id

Index: ports/unittest/logging.ini
===================================================================
--- ports/unittest/logging.ini	(revision 13884)
