Initialization using org.springframework.web.util.Log4jConfigListener entry in web.xml?
java, log4j, spring
Solution
The `Log4jConfigListener` initialises the Log4j "subsystem" as soon the webapplication starts up, as opposed to "lazily configuring" it as soon as it is needed.
In my opinion, the main advantage of explicitly initializing log4j via the Log4JConfigListener is that it allows you to configure the location of the log4j configuration file through using servlet context parameters; depending on how the application is deployed, this may make it possible for the configuration to be changed at runtime by some kind of admin user without having to dig around inside the exploded WAR directory .
See the javadoc for Log4jConfigListener, and more importantly Log4jWebConfigurer, as it does the real work.
Problem
In most of the Java projects using Spring, I find this entry in web.xml which is executed at server start-up: ``` <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> ``` What is the purpose of `Log4jConfigListener`? In my legacy project I can also see this setting. However when i dive into the code I do not find anything special done in this class or further classes called internally by this class. I am sure there must be some good purpose behind putting above code snippet and I am missing it. In every class which putting the logs in file here is the entry ``` private static final Log log = LogFactory.getLog(PoolManagerImpl.class); log.debug("Number of connection pools to create = [" + connection.size() + "]"); ``` Even if I comment out my web.xml entry, logging works fine. So what is it's purpose?