[slf4j-dev] svn commit: r1240 - in slf4j/trunk/slf4j-ext/src: main/java/org/slf4j/ext test/java/org/slf4j/dummyExt
ceki at slf4j.org
ceki at slf4j.org
Thu Nov 20 14:37:02 CET 2008
Author: ceki
Date: Thu Nov 20 14:37:02 2008
New Revision: 1240
Modified:
slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java
slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java
slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/XLoggerTest.java
Log:
Fixed bug 114. Added test case.
If class B extends A, assuming B does not override method x(), the caller
of new B().x() is A and not B
More specifically, XLogger extends LoggerWrapper. When calling xlogger.debug where debug is a method defined in LoggerWrapper not overridden in XLogger, the caller is LoggerWrapper and not XLogger.
Modified: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java (original)
+++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java Thu Nov 20 14:37:02 2008
@@ -27,9 +27,9 @@
// is this logger instance a LocationAwareLogger
final boolean instanceofLAL;
- public LoggerWrapper(Logger logger) {
+ public LoggerWrapper(Logger logger, String fqcn) {
this.logger = logger;
- this.fqcn = LoggerWrapper.class.getName();
+ this.fqcn = fqcn;
if (logger instanceof LocationAwareLogger) {
instanceofLAL = true;
} else {
Modified: slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java (original)
+++ slf4j/trunk/slf4j-ext/src/main/java/org/slf4j/ext/XLogger.java Thu Nov 20 14:37:02 2008
@@ -48,15 +48,16 @@
}
/**
- * Given an underlying logger, constuct an XLogger
+ * Given an underlying logger, construct an XLogger
*
* @param logger
* underlying logger
*/
public XLogger(Logger logger) {
-
- super(logger);
- System.out.println("xxxxxxxxx");
+ // If class B extends A, assuming B does not override method x(), the caller
+ // of new B().x() is A and not B, see also
+ // http://bugzilla.slf4j.org/show_bug.cgi?id=114
+ super(logger, LoggerWrapper.class.getName());
}
/**
Modified: slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/XLoggerTest.java
==============================================================================
--- slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/XLoggerTest.java (original)
+++ slf4j/trunk/slf4j-ext/src/test/java/org/slf4j/dummyExt/XLoggerTest.java Thu Nov 20 14:37:02 2008
@@ -2,6 +2,7 @@
import junit.framework.TestCase;
+import org.apache.log4j.spi.LocationInfo;
import org.apache.log4j.spi.LoggingEvent;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -10,9 +11,9 @@
ListAppender listAppender;
org.apache.log4j.Logger log4jRoot;
-
+
final static String EXPECTED_FILE_NAME = "XLoggerTest.java";
-
+
public XLoggerTest(String name) {
super(name);
}
@@ -33,7 +34,6 @@
super.tearDown();
}
-
void verify(LoggingEvent le, String expectedMsg) {
assertEquals(expectedMsg, le.getMessage());
assertEquals(EXPECTED_FILE_NAME, le.getLocationInformation().getFileName());
@@ -43,7 +43,7 @@
verify(le, expectedMsg);
assertEquals(t.toString(), le.getThrowableStrRep()[0]);
}
-
+
public void testEntering() {
XLogger logger = XLoggerFactory.getXLogger("UnitTest");
logger.entry();
@@ -54,14 +54,14 @@
verify((LoggingEvent) listAppender.list.get(0), "entry");
verify((LoggingEvent) listAppender.list.get(1), "entry with (1)");
verify((LoggingEvent) listAppender.list.get(2), "entry with (test)");
- }
+ }
public void testExiting() {
XLogger logger = XLoggerFactory.getXLogger("UnitTest");
logger.exit();
logger.exit(0);
logger.exit(false);
-
+
assertEquals(3, listAppender.list.size());
verify((LoggingEvent) listAppender.list.get(0), "exit");
verify((LoggingEvent) listAppender.list.get(1), "exit with (0)");
@@ -90,6 +90,30 @@
verifyWithException((LoggingEvent) listAppender.list.get(0), "catching", t);
}
+ // See http://bugzilla.slf4j.org/show_bug.cgi?id=114
+ public void testLocationExtraction_Bug114() {
+ XLogger logger = XLoggerFactory.getXLogger("UnitTest");
+ logger.exit();
+ logger.debug("hello");
+
+ assertEquals(2, listAppender.list.size());
+
+ {
+ LoggingEvent e = listAppender.list.get(0);
+ LocationInfo li = e.getLocationInformation();
+ assertEquals(this.getClass().getName(), li.getClassName());
+ assertEquals("95", li.getLineNumber());
+ }
+
+ {
+ LoggingEvent e = listAppender.list.get(1);
+ LocationInfo li = e.getLocationInformation();
+ assertEquals(this.getClass().getName(), li.getClassName());
+ assertEquals("96", li.getLineNumber());
+ }
+
+ }
+
// public void testDump() {
// XLogger logger = XLoggerFactory.getXLogger("UnitTest");
// String dumpData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Document>\n
@@ -101,5 +125,4 @@
// assertTrue(logMessage.trim().startsWith(expected));
// }
-
}
More information about the slf4j-dev
mailing list