[slf4j-dev] svn commit: r1029 - slf4j/trunk/jul-to-slf4j/src/test/java/org/slf4j/bridgeX

ceki at slf4j.org ceki at slf4j.org
Fri May 30 23:41:02 CEST 2008


Author: ceki
Date: Fri May 30 23:41:02 2008
New Revision: 1029

Added:
   slf4j/trunk/jul-to-slf4j/src/test/java/org/slf4j/bridgeX/
      - copied from r1021, /slf4j/trunk/jul-to-slf4j/src/test/java/org/slf4j/bridge/
   slf4j/trunk/jul-to-slf4j/src/test/java/org/slf4j/bridgeX/SLF4JBridgeHandlerTest.java

Log:
- tested to make sure that location information can be extracted correctly


Added: slf4j/trunk/jul-to-slf4j/src/test/java/org/slf4j/bridgeX/SLF4JBridgeHandlerTest.java
==============================================================================
--- (empty file)
+++ slf4j/trunk/jul-to-slf4j/src/test/java/org/slf4j/bridgeX/SLF4JBridgeHandlerTest.java	Fri May 30 23:41:02 2008
@@ -0,0 +1,48 @@
+package org.slf4j.testBridge;
+
+import org.apache.log4j.spi.LocationInfo;
+import org.apache.log4j.spi.LoggingEvent;
+import org.slf4j.ListAppender;
+import org.slf4j.bridge.SLF4JBridgeHandler;
+
+import junit.framework.TestCase;
+
+public class SLF4JBridgeHandlerTest extends TestCase {
+  
+  static String LOGGER_NAME = "yay";
+  
+  ListAppender listAppender = new ListAppender();
+  org.apache.log4j.Logger log4jRoot;
+  java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger("yay");
+  
+  public SLF4JBridgeHandlerTest(String arg0) {
+    super(arg0);
+  }
+
+  protected void setUp() throws Exception {
+    super.setUp();
+    listAppender.extractLocationInfo = true;
+    log4jRoot = org.apache.log4j.Logger.getRootLogger();
+    log4jRoot.addAppender(listAppender);
+  }
+
+  protected void tearDown() throws Exception {
+    super.tearDown();
+    log4jRoot.getLoggerRepository().resetConfiguration();
+  }
+  
+  public void testSmoke() {
+    SLF4JBridgeHandler.install();
+    String msg = "msg";
+    julLogger.info(msg);
+    assertEquals(1, listAppender.list.size());
+    LoggingEvent le = (LoggingEvent) listAppender.list.get(0);
+    assertEquals(LOGGER_NAME, le.getLoggerName());
+    assertEquals(msg, le.getMessage());
+    
+    LocationInfo li = le.getLocationInformation();
+    System.out.println(li.fullInfo);
+    assertEquals("SLF4JBridgeHandlerTest.java", li.getFileName());
+    assertEquals("testSmoke", li.getMethodName());
+  }
+}



More information about the slf4j-dev mailing list