Question

I am checking out log4j2 via the overview documentation and I am getting the following exception when trying to setup the log4j2 logger:

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.NullPointerException
    at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:129)
    at HelloWorld.<clinit>(HelloWorld.java:5)

My test program is taken from the overview site:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class HelloWorld {
    private static Logger logger = LogManager.getLogger("HelloWorld");
    public static void main(String[] args) {
        logger.info("Hello, World!");
    }
}

I added all the provided jar files from the binary distribution to my build path.

What am I missing?

Was it helpful?

Solution

Simply don't! Use Logback instead of Log4J!

OTHER TIPS

For anyone who stumble across this in the future:

JAR log4j-core-2.0-beta2-sources is the cause of the error. If you remove this JAR from your build path you can build properly.

I opened up a JIRA ticket on the ASF tracker located at https://issues.apache.org/jira/browse/LOG4J2-118 regarding this issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top