I have this simple program:
package myPackage;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class Test {
private static Logger logger;
public static void main(String[] args) throws Exception {
System.out.println("Creating logger...");
logger = LogManager.getLogger(Test.class);
System.out.println("Logger created.");
logger.info("Hello world!");
}
}
If I run the program under the debugger, it prints:
Creating logger...
and then hangs.
If I run the program without debugger, it prints:
Exception in thread "main" java.lang.StackOverflowError
at sun.reflect.Reflection.quickCheckMemberAccess(Reflection.java:84)
at java.lang.reflect.Method.invoke(Method.java:489)
at org.apache.logging.log4j.util.ReflectionUtil.getCallerClass(ReflectionUtil.java:128)
at org.apache.logging.log4j.util.ReflectionUtil.getCallerClass(ReflectionUtil.java:205)
at org.apache.logging.slf4j.Log4jLoggerFactory.getContext(Log4jLoggerFactory.java:42)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:42)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:329)
at org.apache.logging.slf4j.SLF4JLoggerContext.getLogger(SLF4JLoggerContext.java:42)
at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:37)
at org.apache.logging.slf4j.Log4jLoggerFactory.newLogger(Log4jLoggerFactory.java:29)
at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:48)
at org.apache.logging.slf4j.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:29)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:329)
[... more of the same]
I am using Log4j 2 version 2.5 along with SLF4J version 1.7.18.
EDIT: This is my class path:
// JRE 1.8.0_74
// Log4j 2
log4j-1.2-api-2.5.jar
log4j-1.2-api-2.5-javadoc.jar
log4j-1.2-api-2.5-sources.jar
log4j-api-2.5.jar
log4j-api-2.5-javadoc.jar
log4j-api-2.5-sources.jar
log4j-core-2.5.jar
log4j-core-2.5-javadoc.jar
log4j-core-2.5-sources.jar
log4j-core-2.5-tests.jar
log4j-flume-ng-2.5.jar
log4j-flume-ng-2.5-javadoc.jar
log4j-flume-ng-2.5-sources.jar
log4j-iostreams-2.5.jar
log4j-iostreams-2.5-javadoc.jar
log4j-iostreams-2.5-sources.jar
log4j-jcl-2.5.jar
log4j-jcl-2.5-javadoc.jar
log4j-jcl-2.5-sources.jar
log4j-jmx-gui-2.5.jar
log4j-jmx-gui-2.5-javadoc.jar
log4j-jmx-gui-2.5-sources.jar
log4j-jul-2.5.jar
log4j-jul-2.5-javadoc.jar
log4j-jul-2.5-sources.jar
log4j-nosql-2.5.jar
log4j-nosql-2.5-javadoc.jar
log4j-nosql-2.5-sources.jar
log4j-slf4j-impl-2.5.jar
log4j-slf4j-impl-2.5-javadoc.jar
log4j-slf4j-impl-2.5-sources.jar
log4j-taglib-2.5.jar
log4j-taglib-2.5-javadoc.jar
log4j-taglib-2.5-sources.jar
log4j-to-slf4j-2.5.jar
log4j-to-slf4j-2.5-javadoc.jar
log4j-to-slf4j-2.5-sources.jar
log4j-web-2.5.jar
log4j-web-2.5-javadoc.jar
log4j-web-2.5-sources.jar
// SLF4J 1.7.18
slf4j-api-1.7.18.jar