[logback-dev] svn commit: r1979 - in logback/trunk/logback-classic: . src/main/java/ch/qos/logback/classic/pattern src/main/java/ch/qos/logback/classic/selector/servlet src/main/java/org/slf4j/impl src/test src/test/java/ch/qos/logback/classic/net src/test/java/ch/qos/logback/classic/net/mock src/test/java/ch/qos/logback/classic/selector src/test/java/ch/qos/logback/classic/util src/test/java/org/dummy src/test/java/org/slf4j src/test/java/org/slf4j/impl src/test/resources

noreply.ceki at qos.ch noreply.ceki at qos.ch
Thu Nov 20 19:04:55 CET 2008


Author: ceki
Date: Thu Nov 20 19:04:55 2008
New Revision: 1979

Added:
   logback/trunk/logback-classic/src/test/generateRollingLogsInSafeMode.sh
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/MockInitialContext.java
      - copied, changed from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockInitialContext.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/MockInitialContextFactory.java
      - copied, changed from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockInitialContextFactory.java
   logback/trunk/logback-classic/src/test/java/org/slf4j/LoggerFactoryFriend.java
   logback/trunk/logback-classic/src/test/java/org/slf4j/impl/StaticLoggerBinderFriend.java
   logback/trunk/logback-classic/src/test/resources/recursiveInit.xml
Removed:
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockInitialContext.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockInitialContextFactory.java
Modified:
   logback/trunk/logback-classic/pom.xml
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/RelativeTimeConverter.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java
   logback/trunk/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextJNDISelectorTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/PackageTest.java
   logback/trunk/logback-classic/src/test/java/org/dummy/DummyLBAppender.java
   logback/trunk/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java

Log:
LBCLASSIC-87

With each call to getLogger() method, LoggerContext will now retrieve the ILoggerFactory afresh from StaticLoggerBinder. 
This change enables context selectors of native implementations, e.g logback, to work correctly. 

Modified: logback/trunk/logback-classic/pom.xml
==============================================================================
--- logback/trunk/logback-classic/pom.xml	(original)
+++ logback/trunk/logback-classic/pom.xml	Thu Nov 20 19:04:55 2008
@@ -47,6 +47,13 @@
 
     <dependency>
       <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-ext</artifactId>
+      <version>${slf4j.version}</version>
+      <scope>compile</scope>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <type>test-jar</type>
       <version>${slf4j.version}</version>

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/RelativeTimeConverter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/RelativeTimeConverter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/RelativeTimeConverter.java	Thu Nov 20 19:04:55 2008
@@ -1,11 +1,11 @@
 /**
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2006, QOS.ch
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2008, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
  */
 package ch.qos.logback.classic.pattern;
 

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/ContextDetachingSCL.java	Thu Nov 20 19:04:55 2008
@@ -38,7 +38,7 @@
     if (loggerContextName != null) {
       System.out.println("About to detach context named " + loggerContextName);
       
-      ContextSelector selector = StaticLoggerBinder.SINGLETON.getContextSelector();
+      ContextSelector selector = StaticLoggerBinder.getSingleton().getContextSelector();
       LoggerContext context = selector.detachLoggerContext(loggerContextName);
       if (context != null) {
         Logger logger = context.getLogger(LoggerContext.ROOT_NAME);

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/selector/servlet/LoggerContextFilter.java	Thu Nov 20 19:04:55 2008
@@ -57,7 +57,7 @@
       FilterChain chain) throws IOException, ServletException {
 
     LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
-    ContextSelector selector = StaticLoggerBinder.SINGLETON.getContextSelector();
+    ContextSelector selector = StaticLoggerBinder.getSingleton().getContextSelector();
     ContextJNDISelector sel = null;
 
     if (selector instanceof ContextJNDISelector) {

Modified: logback/trunk/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java	(original)
+++ logback/trunk/logback-classic/src/main/java/org/slf4j/impl/StaticLoggerBinder.java	Thu Nov 20 19:04:55 2008
@@ -38,46 +38,61 @@
  */
 public class StaticLoggerBinder implements LoggerFactoryBinder {
 
-  private ContextSelector contextSelector;
+  /**
+   * Declare the version of the SLF4J API this implementation is compiled
+   * against. The value of this field is usually modified with each release.
+   */
+  // to avoid constant folding by the compiler, this field must *not* be final
+  public static String REQUESTED_API_VERSION = "1.5.6"; // !final
 
   final static String NULL_CS_URL = CoreConstants.CODES_URL + "#null_CS";
 
   /**
    * The unique instance of this class.
    */
-  public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
+  private static StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
   
-  /**
-   * Declare the version of the SLF4J API this implementation is compiled against. 
-   * The value of this field is usually modified with each release. 
-   */
-  // to avoid constant folding by the compiler, this field must *not* be final
-  public static String REQUESTED_API_VERSION = "1.5.5";  // !final
-    
-  private static final String loggerFactoryClassStr = ContextSelector.class
-      .getName();
+  static {
+    SINGLETON.init();
+  }
+  
+  private boolean initialized = false;
+  private LoggerContext defaultLoggerContext = new LoggerContext();
+  private ContextSelector contextSelector;
 
+  
   private StaticLoggerBinder() {
-    initialize();
+    defaultLoggerContext.setName("default");
   }
 
-  public void initialize() {
+  public static StaticLoggerBinder getSingleton() {
+    return SINGLETON; 
+  }
+  
+  /**
+   * Package access for testing purposes.
+   */
+  static void reset() {
+    SINGLETON = new StaticLoggerBinder();
+    SINGLETON.init();
+  }
+  
+  /**
+   * Package access for testing purposes.
+   */
+  void init() {
     try {
-      // let's configure a default context
-      LoggerContext defaultLoggerContext = new LoggerContext();
-      defaultLoggerContext.setName("default");
       try {
         new ContextInitializer(defaultLoggerContext).autoConfig();
       } catch (JoranException je) {
-        // TODO test me
         Util.reportFailure("Failed to auto configure default logger context",
             je);
       }
       StatusPrinter.printIfErrorsOccured(defaultLoggerContext);
 
       // See if a special context selector is needed
-      String contextSelectorStr = OptionHelper.getSystemProperty(
-          ClassicGlobal.LOGBACK_CONTEXT_SELECTOR, null);
+      String contextSelectorStr = OptionHelper
+          .getSystemProperty(ClassicGlobal.LOGBACK_CONTEXT_SELECTOR);
       if (contextSelectorStr == null) {
         contextSelector = new DefaultContextSelector(defaultLoggerContext);
       } else if (contextSelectorStr.equals("JNDI")) {
@@ -87,6 +102,7 @@
         contextSelector = dynamicalContextSelector(defaultLoggerContext,
             contextSelectorStr);
       }
+      initialized = true;
     } catch (Throwable t) {
       // we should never get here
       Util.reportFailure("Failed to instantiate ["
@@ -106,6 +122,10 @@
   }
 
   public ILoggerFactory getLoggerFactory() {
+    if(!initialized) {
+      return defaultLoggerContext;
+    }
+    
     if (contextSelector == null) {
       throw new IllegalStateException(
           "contextSelector cannot be null. See also " + NULL_CS_URL);
@@ -114,7 +134,7 @@
   }
 
   public String getLoggerFactoryClassStr() {
-    return loggerFactoryClassStr;
+    return contextSelector.getClass().getName();
   }
 
   /**

Added: logback/trunk/logback-classic/src/test/generateRollingLogsInSafeMode.sh
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/generateRollingLogsInSafeMode.sh	Thu Nov 20 19:04:55 2008
@@ -0,0 +1,40 @@
+echo "File name $1"
+echo "run length $2"
+
+
+
+#On windows
+#CLASSPATH="${CLASSPATH};./target/classes/"
+#CLASSPATH="${CLASSPATH};./target/test-classes/"
+#CLASSPATH="${CLASSPATH};../logback-core/target/classes"
+#CLASSPATH="${CLASSPATH};../logback-examples/lib/slf4j-api-1.5.5.jar"
+
+# On Unix
+#CLASSPATH="${CLASSPATH}:./target/classes/"
+#CLASSPATH="${CLASSPATH}:./target/test-classes/"
+#CLASSPATH="${CLASSPATH}:../logback-core/target/classes"
+#CLASSPATH="${CLASSPATH}:../logback-examples/lib/slf4j-api-1.5.5.jar"
+
+
+if [ $# -lt 3 ]
+then 
+  echo "Usage: generateRollingLogsInSafeMode.sh filename runLen stamp0 ... stampN"
+  exit 1;
+fi
+
+FILENAME=$1
+LEN=$2
+
+shift 2
+
+for stamp in $@
+do 
+  echo running safe mode with $stamp
+  java ch.qos.logback.classic.multiJVM.SafeModeRollingFileAppender $stamp $LEN $FILENAME &
+done
+
+wait
+
+echo "To test the results issue the following command"
+echo "./checkResults.sh $FILENAME $LEN $*"
+

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSQueueAppenderTest.java	Thu Nov 20 19:04:55 2008
@@ -4,12 +4,12 @@
 
 import junit.framework.TestCase;
 import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.net.mock.MockInitialContext;
-import ch.qos.logback.classic.net.mock.MockInitialContextFactory;
 import ch.qos.logback.classic.net.mock.MockQueue;
 import ch.qos.logback.classic.net.mock.MockQueueConnectionFactory;
 import ch.qos.logback.classic.net.mock.MockQueueSender;
 import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.classic.util.MockInitialContext;
+import ch.qos.logback.classic.util.MockInitialContextFactory;
 import ch.qos.logback.core.ContextBase;
 
 public class JMSQueueAppenderTest extends TestCase {

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/JMSTopicAppenderTest.java	Thu Nov 20 19:04:55 2008
@@ -7,12 +7,12 @@
 
 import junit.framework.TestCase;
 import ch.qos.logback.classic.Level;
-import ch.qos.logback.classic.net.mock.MockInitialContext;
-import ch.qos.logback.classic.net.mock.MockInitialContextFactory;
 import ch.qos.logback.classic.net.mock.MockTopic;
 import ch.qos.logback.classic.net.mock.MockTopicConnectionFactory;
 import ch.qos.logback.classic.net.mock.MockTopicPublisher;
 import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.classic.util.MockInitialContext;
+import ch.qos.logback.classic.util.MockInitialContextFactory;
 import ch.qos.logback.core.ContextBase;
 
 public class JMSTopicAppenderTest extends TestCase {

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextDetachingSCLTest.java	Thu Nov 20 19:04:55 2008
@@ -6,9 +6,9 @@
 import org.slf4j.impl.StaticLoggerBinder;
 
 import ch.qos.logback.classic.ClassicGlobal;
-import ch.qos.logback.classic.net.mock.MockInitialContext;
-import ch.qos.logback.classic.net.mock.MockInitialContextFactory;
 import ch.qos.logback.classic.selector.servlet.ContextDetachingSCL;
+import ch.qos.logback.classic.util.MockInitialContext;
+import ch.qos.logback.classic.util.MockInitialContextFactory;
 
 public class ContextDetachingSCLTest extends TestCase {
   
@@ -43,7 +43,7 @@
   }
   
   public void testDetach() {
-    ContextJNDISelector selector = (ContextJNDISelector) StaticLoggerBinder.SINGLETON.getContextSelector();
+    ContextJNDISelector selector = (ContextJNDISelector) StaticLoggerBinder.getSingleton().getContextSelector();
     listener.contextDestroyed(null);
     assertEquals(0, selector.getCount());
   }
@@ -51,14 +51,14 @@
   public void testDetachWithMissingContext() {
     MockInitialContext mic = MockInitialContextFactory.getContext();
     mic.map.put(ClassicGlobal.JNDI_CONTEXT_NAME, "tata");
-    ContextJNDISelector selector = (ContextJNDISelector) StaticLoggerBinder.SINGLETON.getContextSelector();
+    ContextJNDISelector selector = (ContextJNDISelector) StaticLoggerBinder.getSingleton().getContextSelector();
     assertEquals("tata", selector.getLoggerContext().getName());
 
     mic.map.put(ClassicGlobal.JNDI_CONTEXT_NAME, "titi");
     assertEquals("titi", selector.getLoggerContext().getName());
     listener.contextDestroyed(null);
 
-    assertEquals(1, selector.getCount());
+    assertEquals(2, selector.getCount());
   }
   
 }

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextJNDISelectorTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextJNDISelectorTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/ContextJNDISelectorTest.java	Thu Nov 20 19:04:55 2008
@@ -1,25 +1,28 @@
 package ch.qos.logback.classic.selector;
 
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
 
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
 import org.slf4j.LoggerFactory;
 import org.slf4j.impl.StaticLoggerBinder;
+import org.slf4j.impl.StaticLoggerBinderFriend;
 
 import ch.qos.logback.classic.ClassicGlobal;
-import ch.qos.logback.classic.net.mock.MockInitialContext;
-import ch.qos.logback.classic.net.mock.MockInitialContextFactory;
+import ch.qos.logback.classic.util.MockInitialContext;
+import ch.qos.logback.classic.util.MockInitialContextFactory;
 import ch.qos.logback.core.Context;
 
-public class ContextJNDISelectorTest extends TestCase {
+public class ContextJNDISelectorTest  {
   
   static String INITIAL_CONTEXT_KEY = "java.naming.factory.initial";
 
-  @Override
-  protected void setUp() throws Exception {    
-    super.setUp();
+  @Before
+  public void setUp() throws Exception {    
     
     System.setProperty(ClassicGlobal.LOGBACK_CONTEXT_SELECTOR, "JNDI");
-    StaticLoggerBinder.SINGLETON.initialize();
+    StaticLoggerBinderFriend.reset();
     
     MockInitialContextFactory.initialize();
     MockInitialContext mic = MockInitialContextFactory.getContext();
@@ -32,35 +35,38 @@
     LoggerFactory.getLogger(ContextDetachingSCLTest.class);
   }
 
-  @Override
-  protected void tearDown() throws Exception {
+  @After
+  public void tearDown() throws Exception {
     System.clearProperty(INITIAL_CONTEXT_KEY);
-    super.tearDown();
   }
 
+  @Test
   public void testGetExistingContext() {
-    ContextSelector selector = StaticLoggerBinder.SINGLETON.getContextSelector();
+    ContextSelector selector = StaticLoggerBinder.getSingleton().getContextSelector();
     Context context = selector.getLoggerContext();
     assertEquals("toto", context.getName());
   }
   
+  @Test
   public void testCreateContext() {
     MockInitialContext mic = MockInitialContextFactory.getContext();
     mic.map.put(ClassicGlobal.JNDI_CONTEXT_NAME, "tata");
     
     LoggerFactory.getLogger(ContextDetachingSCLTest.class);
     
-    ContextJNDISelector selector = (ContextJNDISelector)StaticLoggerBinder.SINGLETON.getContextSelector();
+    ContextJNDISelector selector = (ContextJNDISelector)StaticLoggerBinder.getSingleton().getContextSelector();
     Context context = selector.getLoggerContext();
     assertEquals("tata", context.getName());
-    assertEquals(1, selector.getCount());
+    System.out.println(selector.getContextNames());
+    assertEquals(2, selector.getCount());
   }
   
-  public void testReturnDefaultContext() {
+  @Test
+  public void defaultContext() {
     MockInitialContext mic = MockInitialContextFactory.getContext();
     mic.map.put(ClassicGlobal.JNDI_CONTEXT_NAME, null);
 
-    ContextJNDISelector selector = (ContextJNDISelector)StaticLoggerBinder.SINGLETON.getContextSelector();
+    ContextJNDISelector selector = (ContextJNDISelector)StaticLoggerBinder.getSingleton().getContextSelector();
     Context context = selector.getLoggerContext();
     
     assertEquals("default", context.getName());    

Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/PackageTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/selector/PackageTest.java	Thu Nov 20 19:04:55 2008
@@ -15,7 +15,7 @@
 
   public static Test suite() {
     TestSuite suite = new TestSuite();
-    suite.addTestSuite(ContextJNDISelectorTest.class);
+    suite.addTest(new JUnit4TestAdapter(ContextJNDISelectorTest.class));
     suite.addTestSuite(ContextDetachingSCLTest.class);
     return suite;
   }

Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/MockInitialContext.java (from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockInitialContext.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockInitialContext.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/MockInitialContext.java	Thu Nov 20 19:04:55 2008
@@ -1,4 +1,4 @@
-package ch.qos.logback.classic.net.mock;
+package ch.qos.logback.classic.util;
 
 import java.util.HashMap;
 import java.util.Map;

Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/MockInitialContextFactory.java (from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockInitialContextFactory.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/mock/MockInitialContextFactory.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/util/MockInitialContextFactory.java	Thu Nov 20 19:04:55 2008
@@ -1,4 +1,4 @@
-package ch.qos.logback.classic.net.mock;
+package ch.qos.logback.classic.util;
 
 import java.util.Hashtable;
 
@@ -6,6 +6,7 @@
 import javax.naming.NamingException;
 import javax.naming.spi.InitialContextFactory;
 
+
 public class MockInitialContextFactory implements InitialContextFactory {
   static MockInitialContext mic;
 

Modified: logback/trunk/logback-classic/src/test/java/org/dummy/DummyLBAppender.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/org/dummy/DummyLBAppender.java	(original)
+++ logback/trunk/logback-classic/src/test/java/org/dummy/DummyLBAppender.java	Thu Nov 20 19:04:55 2008
@@ -1,11 +1,11 @@
 /**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
- *
- * Copyright (C) 1999-2008, QOS.ch
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2008, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
  */
 package org.dummy;
 

Added: logback/trunk/logback-classic/src/test/java/org/slf4j/LoggerFactoryFriend.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/org/slf4j/LoggerFactoryFriend.java	Thu Nov 20 19:04:55 2008
@@ -0,0 +1,16 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2008, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package org.slf4j;
+
+public class LoggerFactoryFriend {
+  static public void reset() {
+    LoggerFactory.reset(); 
+  }
+}

Modified: logback/trunk/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java	Thu Nov 20 19:04:55 2008
@@ -1,7 +1,9 @@
 package org.slf4j.impl;
 
 import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
 
+import java.util.List;
 import java.util.Random;
 
 import org.junit.After;
@@ -9,12 +11,14 @@
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.LoggerFactoryFriend;
 
 import ch.qos.logback.classic.LoggerContext;
 import ch.qos.logback.classic.util.ContextInitializer;
 import ch.qos.logback.core.status.Status;
 import ch.qos.logback.core.status.StatusManager;
 
+
 public class RecursiveInitializationTest {
 
   int diff = new Random().nextInt();
@@ -23,6 +27,7 @@
   public void setUp() throws Exception {
     System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY,
         "recursiveInit.xml");
+    LoggerFactoryFriend.reset();
   }
 
   @After
@@ -40,8 +45,23 @@
         .getILoggerFactory();
     StatusManager sm = loggerContext.getStatusManager();
 
-    assertEquals("Initialization should proceed without errors:", sm.getLevel(),
-        Status.INFO);
-  }
+    assertEquals("Was expecting no errors", Status.INFO, sm.getLevel());
+    
+    List<Status> statusList = sm.getCopyOfStatusList();
+//    int errorCount = 0;
+//    
+//    for(Status s: statusList) {
+//      if(s.getLevel() == Status.ERROR) {
+//        errorCount++;
+//        System.out.println("==========================");
+//        System.out.println(s);
+//        System.out.println("==========================");
+//        
+//        assertNull("Status ["+s+"] has a throwable", s.getThrowable());
+//      }
+//    }
+    // Error msg: No appenders present in context [default] for logger [ResursiveLBAppender..].
+//    assertEquals("Expecting only one error", 1, errorCount);
+    }
 
 }

Added: logback/trunk/logback-classic/src/test/java/org/slf4j/impl/StaticLoggerBinderFriend.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/org/slf4j/impl/StaticLoggerBinderFriend.java	Thu Nov 20 19:04:55 2008
@@ -0,0 +1,26 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 2000-2008, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package org.slf4j.impl;
+
+/**
+ * This class grants public access to package protected methods of
+ * StaticLoggerBinder. Used for testing purposes.
+ * 
+ * @author Ceki Gulcu
+ * 
+ */
+public class StaticLoggerBinderFriend {
+ 
+  static public void reset() {
+    StaticLoggerBinder.reset();
+  }
+
+}

Added: logback/trunk/logback-classic/src/test/resources/recursiveInit.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/resources/recursiveInit.xml	Thu Nov 20 19:04:55 2008
@@ -0,0 +1,18 @@
+<configuration>
+
+  <appender name="STDOUT"
+    class="ch.qos.logback.core.ConsoleAppender">
+    <layout class="ch.qos.logback.classic.PatternLayout">
+      <param name="Pattern"
+        value="TEST %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n" />
+    </layout>
+  </appender>
+
+                                               
+  <appender name="RECURSIVE"  class="org.slf4j.impl.RecursiveLBAppender"/>
+    
+  <root level="DEBUG" >
+    <appender-ref ref="STDOUT" />
+     <appender-ref ref="RECURSIVE" />
+  </root>
+</configuration>
\ No newline at end of file


More information about the logback-dev mailing list