[logback-dev] svn commit: r1977 - logback/trunk/logback-classic/src/test/java/org/dummy

noreply.ceki at qos.ch noreply.ceki at qos.ch
Tue Nov 18 20:40:42 CET 2008


Author: ceki
Date: Tue Nov 18 20:40:42 2008
New Revision: 1977

Added:
   logback/trunk/logback-classic/src/test/java/org/dummy/RecursiveInitializationTest.java
   logback/trunk/logback-classic/src/test/java/org/dummy/RecursiveLBAppender.java
Modified:
   logback/trunk/logback-classic/src/test/java/org/dummy/Log4jInvocation.java

Log:
- adding a very important test checking that initialization of 
  logback can succeed even in presence of recursive calls
  to LoggerFactory.getLogger (invoked during the initialization of
  logback). See also http://bugzilla.slf4j.org/show_bug.cgi?id=106
  and http://jira.qos.ch/browse/LBCORE-47
  
  This test fails if SLF4J 1.5.5 is used.
  
  Related to http://bugzilla.slf4j.org/show_bug.cgi?id=113
  and http://jira.qos.ch/browse/LBCORE-51

Modified: logback/trunk/logback-classic/src/test/java/org/dummy/Log4jInvocation.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/org/dummy/Log4jInvocation.java	(original)
+++ logback/trunk/logback-classic/src/test/java/org/dummy/Log4jInvocation.java	Tue Nov 18 20:40:42 2008
@@ -1,3 +1,12 @@
+/**
+ * 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;
 
 import static org.junit.Assert.assertEquals;
@@ -12,6 +21,12 @@
 import ch.qos.logback.classic.PatternLayout;
 import ch.qos.logback.classic.spi.LoggingEvent;
 
+/**
+ * Used to test log4j-over-slf4j
+ * 
+ * @author Ceki Gulcu
+ *
+ */
 public class Log4jInvocation {
 
   static final String HELLO = "Hello";

Added: logback/trunk/logback-classic/src/test/java/org/dummy/RecursiveInitializationTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/org/dummy/RecursiveInitializationTest.java	Tue Nov 18 20:40:42 2008
@@ -0,0 +1,47 @@
+package org.dummy;
+
+import static org.junit.Assert.*;
+
+import java.util.Random;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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();
+
+  @Before
+  public void setUp() throws Exception {
+    System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY,
+        "recursiveInit.xml");
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    System.clearProperty(ContextInitializer.CONFIG_FILE_PROPERTY);
+  }
+
+  @Test
+  public void recursiveLogbackInitialization() {
+    Logger logger = LoggerFactory.getLogger("RecursiveInitializationTest"
+        + diff);
+    logger.info("RecursiveInitializationTest");
+
+    LoggerContext loggerContext = (LoggerContext) LoggerFactory
+        .getILoggerFactory();
+    StatusManager sm = loggerContext.getStatusManager();
+
+    assertEquals("Initialization should proceed without errors:", sm.getLevel(),
+        Status.INFO);
+  }
+
+}

Added: logback/trunk/logback-classic/src/test/java/org/dummy/RecursiveLBAppender.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/org/dummy/RecursiveLBAppender.java	Tue Nov 18 20:40:42 2008
@@ -0,0 +1,53 @@
+/**
+ * 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;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.qos.logback.classic.PatternLayout;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.AppenderBase;
+
+public class RecursiveLBAppender extends AppenderBase<LoggingEvent> {
+
+  public List<LoggingEvent> list = new ArrayList<LoggingEvent>();
+  public List<String> stringList = new ArrayList<String>();
+  
+  PatternLayout layout;
+  
+  public RecursiveLBAppender() {
+    this(null);
+  }
+  
+  public RecursiveLBAppender(PatternLayout layout) {
+    this.layout = layout;
+  }
+  
+  @Override
+  public void start() {
+    int diff = new Random().nextInt();
+    Logger logger = LoggerFactory.getLogger("ResursiveLBAppender"+diff);
+    logger.info("testing");
+    super.start();
+  }
+  
+  protected void append(LoggingEvent e) {
+    list.add(e);
+    if(layout != null) {
+      String s = layout.doLayout(e);
+      stringList.add(s);
+    }
+  }
+}


More information about the logback-dev mailing list