mirror of https://github.com/qos-ch/slf4j
Fixed bug 139. See also http://bugzilla.slf4j.org/show_bug.cgi?id=139
This commit is contained in:
parent
0ed227329c
commit
fc06663703
|
|
@ -31,7 +31,8 @@ import org.slf4j.spi.LocationAwareLogger;
|
|||
* Log4j's <code>trace</code>, <code>debug()</code>, <code>info()</code>,
|
||||
* <code>warn()</code>, <code>error()</code> printing methods are directly
|
||||
* mapped to their SLF4J equivalents. Log4j's <code>fatal()</code> printing
|
||||
* method is mapped to SLF4J's <code>error()</code> method with a FATAL marker.
|
||||
* method is mapped to SLF4J's <code>error()</code> method with a FATAL
|
||||
* marker.
|
||||
*
|
||||
* @author Sébastien Pennec
|
||||
* @author Ceki Gülcü
|
||||
|
|
@ -147,7 +148,7 @@ public class Category {
|
|||
* SLF4J equivalent, except for FATAL which is mapped as ERROR.
|
||||
*
|
||||
* @param p
|
||||
* the priority to check against
|
||||
* the priority to check against
|
||||
* @return true if this logger is enabled for the given level, false
|
||||
* otherwise.
|
||||
*/
|
||||
|
|
@ -199,7 +200,8 @@ public class Category {
|
|||
* Delegates to {@link org.slf4j.Logger#debug(String)} method of SLF4J.
|
||||
*/
|
||||
public void debug(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT, message, null);
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT,
|
||||
message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -207,14 +209,16 @@ public class Category {
|
|||
* SLF4J.
|
||||
*/
|
||||
public void debug(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT, message, t);
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.DEBUG_INT,
|
||||
message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#info(String)} method in SLF4J.
|
||||
*/
|
||||
public void info(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT, message, null);
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT,
|
||||
message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -222,14 +226,16 @@ public class Category {
|
|||
* SLF4J.
|
||||
*/
|
||||
public void info(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT, message, t);
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.INFO_INT,
|
||||
message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#warn(String)} method in SLF4J.
|
||||
*/
|
||||
public void warn(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT, message, null);
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT,
|
||||
message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -237,14 +243,16 @@ public class Category {
|
|||
* SLF4J.
|
||||
*/
|
||||
public void warn(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT, message, t);
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.WARN_INT,
|
||||
message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#error(String)} method in SLF4J.
|
||||
*/
|
||||
public void error(Object message) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, null);
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT,
|
||||
message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -252,14 +260,16 @@ public class Category {
|
|||
* SLF4J.
|
||||
*/
|
||||
public void error(Object message, Throwable t) {
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, t);
|
||||
differentiatedLog(null, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT,
|
||||
message, t);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegates to {@link org.slf4j.Logger#error(String)} method in SLF4J.
|
||||
*/
|
||||
public void fatal(Object message) {
|
||||
differentiatedLog(FATAL_MARKER, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, null);
|
||||
differentiatedLog(FATAL_MARKER, CATEGORY_FQCN,
|
||||
LocationAwareLogger.ERROR_INT, message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -267,9 +277,11 @@ public class Category {
|
|||
* SLF4J. In addition, the call is marked with a marker named "FATAL".
|
||||
*/
|
||||
public void fatal(Object message, Throwable t) {
|
||||
differentiatedLog(FATAL_MARKER, CATEGORY_FQCN, LocationAwareLogger.ERROR_INT, message, t);
|
||||
differentiatedLog(FATAL_MARKER, CATEGORY_FQCN,
|
||||
LocationAwareLogger.ERROR_INT, message, t);
|
||||
}
|
||||
|
||||
|
||||
public void log(String FQCN, Priority p, Object msg, Throwable t) {
|
||||
int levelInt = priorityToLevelInt(p);
|
||||
if (locationAwareLogger != null) {
|
||||
|
|
@ -280,6 +292,19 @@ public class Category {
|
|||
}
|
||||
}
|
||||
|
||||
public void log(Priority p, Object message, Throwable t) {
|
||||
int levelInt = priorityToLevelInt(p);
|
||||
differentiatedLog(null, CATEGORY_FQCN, levelInt,
|
||||
message, t);
|
||||
}
|
||||
|
||||
public void log(Priority p, Object message) {
|
||||
int levelInt = priorityToLevelInt(p);
|
||||
differentiatedLog(null, CATEGORY_FQCN, levelInt,
|
||||
message, null);
|
||||
}
|
||||
|
||||
|
||||
private int priorityToLevelInt(Priority p) {
|
||||
switch (p.level) {
|
||||
case Level.TRACE_INT:
|
||||
|
|
|
|||
|
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2009 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.apache.log4j;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,27 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2009 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.dummy;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2004-2009 QOS.ch
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.dummy;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.apache.log4j.Category;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class Bug139 extends TestCase {
|
||||
|
||||
public void test() {
|
||||
ListHandler listHandler = new ListHandler();
|
||||
java.util.logging.Logger root = java.util.logging.Logger.getLogger("");
|
||||
root.addHandler(listHandler);
|
||||
root.setLevel(Level.FINEST);
|
||||
Logger log4jLogger = Logger.getLogger("a");
|
||||
Category log4jCategory = Logger.getLogger("b");
|
||||
|
||||
int n = 0;
|
||||
|
||||
log4jLogger.log(org.apache.log4j.Level.DEBUG, "hello"+(++n));
|
||||
log4jCategory.log(org.apache.log4j.Level.DEBUG, "world"+(++n));
|
||||
|
||||
assertEquals(n, listHandler.list.size());
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
LogRecord logRecord = (LogRecord) listHandler.list.get(i);
|
||||
assertEquals("test", logRecord.getSourceMethodName());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue