log4j2 Element Appenders NullPointerException – how to fix it

LOG4j2 is different than LOG4j in many ways. First, LOG4j2 property file is defined in totally different way. If you are going to upgrade to LOG4j2, my recommendation is to spend sometime to understand how to configure. The property file is not as intuitive as in the previous version. Also, we have grown so familiar with the LOG4j that it is a bit of mind shift to get the new version configured properly.

Having said about the configuration, I have encountered following null pointer error. It was strange as in some situation, the error showed and in other it did not. However, with further investigation, I also found the “ERROR” that indicates which log4j properties file it is reading. In my case, it is the old property file that it is reading. I deleted the old and put in the new log4j2.xml file, the error went away and the log4j initialized properly.

element Appenders. java.lang.NullPointerException

main ERROR Unable to locate appender "STDOU" for logger config "root"
main ERROR Unable to locate appender "RollingFile" for logger config "com.example.my.app"