Java – Reinitialize log4j on web app deployment using Log4jConfigListener

javajbosslog4j

I have setup Log4jConfigListener in my web.xml and it works fine, however, if I redeploy the web app without restarting the server then log4j shuts down and does not reinitialize. If I remove the Log4jConfigListener from my web.xml then everything works fine.

I am using JBoss 4.2.3-GA as the app server. I notice that when I am not using the config listener then I do not see any output that Log4J was shutdown, so perhaps the issue is that the web app is shutting down JBoss's log4j LogManager.

Is there a way to configure it properly, or should I avoid using Log4jConfigListener in development?

Best Answer

Log4jConfigListener doesn't really play nice in situations where the app server manages log4j itself (as it does in this case). The two are going to end up getting into a tug-of-war over who gets to configure log4j.

I suggest not using Log4jConfigListener with JBoss, and rely instead on JBoss's own log4j configuration.