avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-logkit/src/test/org/apache/log/test LoggerListenerTestCase.java RecordingLoggerListener.java
Date Mon, 03 Feb 2003 19:39:39 GMT
bloritsch    2003/02/03 11:39:39

  Added:       src/java/org/apache/log/util LoggerListener.java
               src/test/org/apache/log/test LoggerListenerTestCase.java
                        RecordingLoggerListener.java
  Log:
  add missing files
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-logkit/src/java/org/apache/log/util/LoggerListener.java
  
  Index: LoggerListener.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.log.util;
  
  import org.apache.log.Logger;
  
  /**
   * The LoggerListener class is used to notify listeners
   * when a new Logger object is created. Loggers are created
   * when a client requests a new Logger via {@link Logger#getChildLogger}.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public abstract class LoggerListener
  {
      /**
       * Notify listener that Logger was created.
       *
       * @param category the error message
       * @param logger the logger that was created
       */
      public abstract void loggerCreated( String category, Logger logger );
  }
  
  
  
  1.1                  jakarta-avalon-logkit/src/test/org/apache/log/test/LoggerListenerTestCase.java
  
  Index: LoggerListenerTestCase.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.log.test;
  
  import junit.framework.TestCase;
  import org.apache.log.Hierarchy;
  import org.apache.log.Logger;
  
  /**
   * Test suite for logger listener features of Logger.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public final class LoggerListenerTestCase
      extends TestCase
  {
      public LoggerListenerTestCase( final String name )
      {
          super( name );
      }
  
      public void testPriorityInheritance()
          throws Exception
      {
          final RecordingLoggerListener listener = new RecordingLoggerListener();
          final Hierarchy hierarchy = new Hierarchy();
          hierarchy.setLoggerListener( listener );
  
          final Logger root = hierarchy.getRootLogger();
          final Logger l1 = root.getChildLogger( "logger1" );
          final Logger l2 = root.getChildLogger( "logger2" );
          final Logger l3 = root.getChildLogger( "logger1.logger3" );
          final Logger l4 = root.getChildLogger( "logger5.logger4" );
          final Logger l5 = root.getChildLogger( "logger5" );
  
          final Logger[] loggers = listener.getLoggers();
          assertEquals( "Logger Count", 5, loggers.length );
          assertEquals( "Logger[0]", l1, loggers[ 0 ] );
          assertEquals( "Logger[1]", l2, loggers[ 1 ] );
          assertEquals( "Logger[2]", l3, loggers[ 2 ] );
          assertEquals( "Logger[3]", l5, loggers[ 3 ] );
          assertEquals( "Logger[4]", l4, loggers[ 4 ] );
      }
  }
  
  
  
  1.1                  jakarta-avalon-logkit/src/test/org/apache/log/test/RecordingLoggerListener.java
  
  Index: RecordingLoggerListener.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.log.test;
  
  import java.util.ArrayList;
  import java.util.List;
  import org.apache.log.Logger;
  import org.apache.log.util.LoggerListener;
  
  /**
   * A logger listener that records the log messages it receives.
   *
   * @author <a href="mailto:peter at realityforge.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2003/02/03 19:39:39 $
   */
  class RecordingLoggerListener
      extends LoggerListener
  {
      //The listeners that have been created
      private final List m_loggers = new ArrayList();
  
      public void loggerCreated( final String category,
                                 final Logger logger )
      {
          m_loggers.add( logger );
      }
  
      public Logger[] getLoggers()
      {
          return (Logger[])m_loggers.toArray( new Logger[ m_loggers.size() ] );
      }
  }
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-cvs-help@jakarta.apache.org


Mime
View raw message