diff --git a/log4j-weaver/src/main/java/org/apache/logging/log4j/weaver/log4j2/LoggerConversionHandler.java b/log4j-weaver/src/main/java/org/apache/logging/log4j/weaver/log4j2/LoggerConversionHandler.java index 05878744..e419fcc3 100644 --- a/log4j-weaver/src/main/java/org/apache/logging/log4j/weaver/log4j2/LoggerConversionHandler.java +++ b/log4j-weaver/src/main/java/org/apache/logging/log4j/weaver/log4j2/LoggerConversionHandler.java @@ -132,17 +132,6 @@ public void handleMethodInstruction(LocationMethodVisitor mv, String name, Strin case "throwing": handleCatchingThrowing(mv, descriptor, "throwing".equals(name)); break; - case "isDebugEnabled": - case "isEnabled": - case "isErrorEnabled": - case "isFatalEnabled": - case "isInfoEnabled": - case "isTraceEnabled": - case "isWarnEnabled": - case "logMessage": - // These are NOPs - mv.invokeInterface(LOGGER_TYPE, new Method(name, descriptor)); - break; case "traceEntry": handleTraceEntry(mv, descriptor); break; @@ -150,7 +139,8 @@ public void handleMethodInstruction(LocationMethodVisitor mv, String name, Strin handleTraceExit(mv, descriptor); break; default: - throw new ConversionException("Unsupported method 'org.apache.logging.log4j.Logger#" + name + "'."); + // The default is to not change the original call + mv.invokeInterface(LOGGER_TYPE, new Method(name, descriptor)); } } diff --git a/log4j-weaver/src/test/java/org/apache/logging/log4j/weaver/log4j2/LoggerConversionHandlerExample.java b/log4j-weaver/src/test/java/org/apache/logging/log4j/weaver/log4j2/LoggerConversionHandlerExample.java index e56048bd..ae8ae598 100644 --- a/log4j-weaver/src/test/java/org/apache/logging/log4j/weaver/log4j2/LoggerConversionHandlerExample.java +++ b/log4j-weaver/src/test/java/org/apache/logging/log4j/weaver/log4j2/LoggerConversionHandlerExample.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import java.util.List; import org.apache.logging.log4j.Level; @@ -62,753 +63,741 @@ public class LoggerConversionHandlerExample { private static final Logger logger = LogManager.getLogger(); - private static final int referenceLine = 65; - public void testFatal(final ListAppender app) { app.clear(); final String methodName = "testFatal"; - int lineNumber = referenceLine + 5; // current line number logger.fatal(CHAR_SEQUENCE); - assertLocationEquals(methodName, ++lineNumber, app); + assertLocationEquals(methodName, app); logger.fatal(CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, CHAR_SEQUENCE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(() -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(() -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, () -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, () -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(() -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(() -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, () -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, () -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.fatal(MARKER, STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); } public void testError(final ListAppender app) { app.clear(); final String methodName = "testError"; - int lineNumber = referenceLine + 103; // current line number logger.error(CHAR_SEQUENCE); - assertLocationEquals(methodName, ++lineNumber, app); + assertLocationEquals(methodName, app); logger.error(CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, CHAR_SEQUENCE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(() -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(() -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, () -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, () -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(() -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(() -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, () -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, () -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.error(MARKER, STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); } public void testWarn(final ListAppender app) { app.clear(); final String methodName = "testWarn"; - int lineNumber = referenceLine + 201; // current line number logger.warn(CHAR_SEQUENCE); - assertLocationEquals(methodName, ++lineNumber, app); + assertLocationEquals(methodName, app); logger.warn(CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, CHAR_SEQUENCE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(() -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(() -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, () -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, () -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(() -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(() -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, () -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, () -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.warn(MARKER, STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); } public void testInfo(final ListAppender app) { app.clear(); final String methodName = "testInfo"; - int lineNumber = referenceLine + 299; // current line number logger.info(CHAR_SEQUENCE); - assertLocationEquals(methodName, ++lineNumber, app); + assertLocationEquals(methodName, app); logger.info(CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, CHAR_SEQUENCE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(() -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(() -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, () -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, () -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(() -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(() -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, () -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, () -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.info(MARKER, STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); } public void testDebug(final ListAppender app) { app.clear(); final String methodName = "testDebug"; - int lineNumber = referenceLine + 397; // current line number logger.debug(CHAR_SEQUENCE); - assertLocationEquals(methodName, ++lineNumber, app); + assertLocationEquals(methodName, app); logger.debug(CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, CHAR_SEQUENCE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(() -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(() -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, () -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, () -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(() -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(() -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, () -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, () -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.debug(MARKER, STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); } public void testTrace(final ListAppender app) { app.clear(); final String methodName = "testTrace"; - int lineNumber = referenceLine + 495; // current line number logger.trace(CHAR_SEQUENCE); - assertLocationEquals(methodName, ++lineNumber, app); + assertLocationEquals(methodName, app); logger.trace(CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, CHAR_SEQUENCE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(() -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(() -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, () -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, () -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(() -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(() -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, () -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, () -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.trace(MARKER, STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); } public void testLog(final ListAppender app) { app.clear(); final String methodName = "testLog"; - int lineNumber = referenceLine + 593; // current line number logger.log(Level.INFO, CHAR_SEQUENCE); - assertLocationEquals(methodName, ++lineNumber, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, CHAR_SEQUENCE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, CHAR_SEQUENCE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, P0); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, P0, P1); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, P0, P1, P2); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, P0, P1, P2, P3); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, P0, P1, P2, P3, P4); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, P0, P1, P2, P3, P4, P5); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, P0, P1, P2, P3, P4, P5, P6); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, P0, P1, P2, P3, P4, P5, P6, P7, P8, P9); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, PARRAY); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, () -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, () -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, () -> MESSAGE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, () -> MESSAGE, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, () -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, () -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, () -> OBJECT); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, () -> OBJECT, THROWABLE); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.log(Level.INFO, MARKER, STRING, SUPPLIERS); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); } public void testFrames(final ListAppender app) { app.clear(); final String methodName = "testFrames"; - final int lineNumber = referenceLine + 691; // Current line int i = 0; while (i < 2) { if (i < 1) { logger.debug(OBJECT); - assertLocationEquals(methodName, lineNumber + 4, app); + assertLocationEquals(methodName, app); } else { logger.debug(OBJECT); - assertLocationEquals(methodName, lineNumber + 7, app); + assertLocationEquals(methodName, app); } logger.debug(OBJECT); - assertLocationEquals(methodName, lineNumber + 10, app); + assertLocationEquals(methodName, app); i++; } switch (i) { case 2: logger.debug(OBJECT); - assertLocationEquals(methodName, lineNumber + 16, app); + assertLocationEquals(methodName, app); break; } for (; i >= 0; i--) { logger.debug(OBJECT); - assertLocationEquals(methodName, lineNumber + 21, app); + assertLocationEquals(methodName, app); } } public void testPrintf(final ListAppender app) { app.clear(); final String methodName = "testPrintf"; - int lineNumber = referenceLine + 720; // Current line logger.printf(Level.INFO, "Hello %s.%s", "LoggerConversionHandlerExample", methodName); - assertLocationEquals(methodName, ++lineNumber, app); + assertLocationEquals(methodName, app); logger.printf(Level.INFO, MARKER, "Hello %s.%s", "LoggerConversionHandlerExample", methodName); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); } public void testLogBuilder(final ListAppender app) { app.clear(); final String methodName = "testLogBuilder"; - int lineNumber = referenceLine + 730; // Current line logger.always().log(); - assertLocationEquals(methodName, ++lineNumber, app); + assertLocationEquals(methodName, app); logger.atDebug().log(); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.atError().log(); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.atFatal().log(); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.atInfo().log(); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.atLevel(Level.INFO).log(); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.atTrace().log(); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); logger.atWarn().log(); - assertLocationEquals(methodName, lineNumber += 2, app); + assertLocationEquals(methodName, app); } /** @@ -829,6 +818,10 @@ public void testPassthrough(final ListAppender app) { assertTrue(logger.isTraceEnabled(MARKER)); assertTrue(logger.isWarnEnabled()); assertTrue(logger.isWarnEnabled(MARKER)); + assertDoesNotThrow(logger::getName); + assertDoesNotThrow(logger::getLevel); + assertDoesNotThrow(logger::getFlowMessageFactory); + assertDoesNotThrow(logger::getClass); app.clear(); logger.logMessage(Level.INFO, MARKER, LoggerConversionHandlerExample.class.getName(), null, MESSAGE, THROWABLE); assertThat(app.getEvents()).hasSize(1); @@ -837,47 +830,45 @@ public void testPassthrough(final ListAppender app) { public void testCatchingThrowing(final ListAppender app) { app.clear(); final String methodName = "testCatchingThrowing"; - int lineNumber = referenceLine + 775; // Current line logger.catching(THROWABLE); assertThat(app.getEvents()).allMatch(event -> AbstractLogger.CATCHING_MARKER.equals(event.getMarker())); - assertLocationEquals(methodName, ++lineNumber, app); + assertLocationEquals(methodName, app, 2); logger.catching(Level.INFO, THROWABLE); assertThat(app.getEvents()).allMatch(event -> AbstractLogger.CATCHING_MARKER.equals(event.getMarker())); - assertLocationEquals(methodName, lineNumber += 3, app); + assertLocationEquals(methodName, app, 2); assertThat(logger.throwing(THROWABLE)).isInstanceOf(RuntimeException.class); assertThat(app.getEvents()).allMatch(event -> AbstractLogger.THROWING_MARKER.equals(event.getMarker())); - assertLocationEquals(methodName, lineNumber += 3, app); + assertLocationEquals(methodName, app, 2); assertThat(logger.throwing(THROWABLE)).isInstanceOf(RuntimeException.class); assertThat(app.getEvents()).allMatch(event -> AbstractLogger.THROWING_MARKER.equals(event.getMarker())); - assertLocationEquals(methodName, lineNumber += 3, app); + assertLocationEquals(methodName, app, 2); } public void testTraceEntry(final ListAppender app) { app.clear(); final String methodName = "testTraceEntry"; - int lineNumber = referenceLine + 793; // Current line EntryMessage entryMessage = logger.traceEntry(); - LogEvent event = assertLocationEquals(methodName, ++lineNumber, app); + LogEvent event = assertLocationEquals(methodName, app); assertThat(event.getMarker()).isEqualTo(AbstractLogger.ENTRY_MARKER); assertThat(entryMessage.getMessage()).isNull(); entryMessage = logger.traceEntry(MESSAGE); - event = assertLocationEquals(methodName, lineNumber += 5, app); + event = assertLocationEquals(methodName, app); assertThat(event.getMarker()).isEqualTo(AbstractLogger.ENTRY_MARKER); assertThat(entryMessage.getMessage()).isEqualTo(MESSAGE); entryMessage = logger.traceEntry("param1 = {}", PARRAY); - event = assertLocationEquals(methodName, lineNumber += 5, app); + event = assertLocationEquals(methodName, app); assertThat(event.getMarker()).isEqualTo(AbstractLogger.ENTRY_MARKER); assertThat(entryMessage.getFormattedMessage()).isEqualTo("Enter param1 = (...)"); entryMessage = logger.traceEntry(() -> P0, () -> P1); - event = assertLocationEquals(methodName, lineNumber += 5, app); + event = assertLocationEquals(methodName, app); assertThat(event.getMarker()).isEqualTo(AbstractLogger.ENTRY_MARKER); assertThat(entryMessage.getFormattedMessage()).isEqualTo("Enter params((p0), (p1))"); entryMessage = logger.traceEntry("param1 = {}, param2 = {}", () -> P0, () -> P1); - event = assertLocationEquals(methodName, lineNumber += 5, app); + event = assertLocationEquals(methodName, app); assertThat(event.getMarker()).isEqualTo(AbstractLogger.ENTRY_MARKER); assertThat(entryMessage.getFormattedMessage()).isEqualTo("Enter param1 = (p0), param2 = (p1)"); } @@ -885,50 +876,67 @@ public void testTraceEntry(final ListAppender app) { public void testTraceExit(final ListAppender app) { app.clear(); final String methodName = "testTraceExit"; - int lineNumber = referenceLine + 823; // Current line logger.traceExit(); - LogEvent event = assertLocationEquals(methodName, ++lineNumber, app); + LogEvent event = assertLocationEquals(methodName, app); assertThat(event.getMarker()).isEqualTo(AbstractLogger.EXIT_MARKER); assertThat(event.getMessage()).isInstanceOf(ExitMessage.class); assertThat(event.getMessage().getFormattedMessage()).isEqualTo("Exit"); logger.traceExit(ENTRY_MESSAGE); - event = assertLocationEquals(methodName, lineNumber += 6, app); + event = assertLocationEquals(methodName, app); assertThat(event.getMarker()).isEqualTo(AbstractLogger.EXIT_MARKER); assertThat(event.getMessage()).isInstanceOf(ExitMessage.class); assertThat(event.getMessage().getFormattedMessage()).isEqualTo("Exit (Message)"); Object result = logger.traceExit(OBJECT); assertThat(result).isSameAs(OBJECT); - event = assertLocationEquals(methodName, lineNumber += 6, app); + event = assertLocationEquals(methodName, app, 2); assertThat(event.getMarker()).isEqualTo(AbstractLogger.EXIT_MARKER); assertThat(event.getMessage()).isInstanceOf(ExitMessage.class); assertThat(event.getMessage().getFormattedMessage()).isEqualTo("Exit with((Object))"); result = logger.traceExit("result = {}", OBJECT); assertThat(result).isSameAs(OBJECT); - event = assertLocationEquals(methodName, lineNumber += 7, app); + event = assertLocationEquals(methodName, app, 2); assertThat(event.getMarker()).isEqualTo(AbstractLogger.EXIT_MARKER); assertThat(event.getMessage()).isInstanceOf(ExitMessage.class); assertThat(event.getMessage().getFormattedMessage()).isEqualTo("Exit result = (Object)"); result = logger.traceExit(MESSAGE, OBJECT); assertThat(result).isSameAs(OBJECT); - event = assertLocationEquals(methodName, lineNumber += 7, app); + event = assertLocationEquals(methodName, app, 2); assertThat(event.getMarker()).isEqualTo(AbstractLogger.EXIT_MARKER); assertThat(event.getMessage()).isInstanceOf(ExitMessage.class); assertThat(event.getMessage().getFormattedMessage()).isEqualTo("Exit (Message): (Object)"); result = logger.traceExit(ENTRY_MESSAGE, OBJECT); assertThat(result).isSameAs(OBJECT); - event = assertLocationEquals(methodName, lineNumber += 7, app); + event = assertLocationEquals(methodName, app, 2); assertThat(event.getMarker()).isEqualTo(AbstractLogger.EXIT_MARKER); assertThat(event.getMessage()).isInstanceOf(ExitMessage.class); assertThat(event.getMessage().getFormattedMessage()).isEqualTo("Exit (Message): (Object)"); } - private static LogEvent assertLocationEquals( - final String methodName, final int lineNumber, final ListAppender app) { + /** + * Asserts log event has the right location intended, the log request should right before this call + * + * @param methodName method name of the calling function + * @param app list appender + * @return the log event extracted + */ + private static LogEvent assertLocationEquals(final String methodName, final ListAppender app) { + return assertLocationEquals(methodName, app, -1); + } + + /** + * Asserts log event has the right location intended, the log request is {@param difference} before this call + * + * @param methodName method name of the calling function + * @param app list appender + * @param difference the difference between the call to this function and the log + * @return the log event extracted + */ + private static LogEvent assertLocationEquals(final String methodName, final ListAppender app, int difference) { final List events = app.getEvents(); assertThat(events).hasSize(1); final LogEvent event = events.get(0); @@ -938,8 +946,16 @@ private static LogEvent assertLocationEquals( assertThat(location.getClassName()).isEqualTo(LoggerConversionHandlerExample.class.getName()); assertThat(location.getMethodName()).isEqualTo(methodName); assertThat(location.getFileName()).isEqualTo("LoggerConversionHandlerExample.java"); - assertThat(location.getLineNumber()).isEqualTo(lineNumber); + if (difference < 0) { + assertThat(location.getLineNumber()).isEqualTo(getCallerLineNumber(true) - 1); + } else { + assertThat(location.getLineNumber()).isEqualTo(getCallerLineNumber(false) - difference); + } app.clear(); return event; } + + private static int getCallerLineNumber(boolean isNested) { + return Thread.currentThread().getStackTrace()[3 + (isNested ? 1 : 0)].getLineNumber(); + } }