Now that is a good idea, John, and definately food for thought.
I would like to show my appreciation for this idea, by contributing to some additional food for thought.
To place the log4j initialization code into a file outside of the web application, and then use a JNDI environment variable in tomcat so that it is indirected from the web application, the log4j init gets the path to its config file as the value of a
string environment variable.
This saves me time when i have to build a war file, i can just move it from dev instance (debug on) to the prod instance (debug off), since the logging, (among other things) is now configured in a server instance, and not the web app module.
I guess it is what JNDI DataSources are to database connections, for the log4j configuration.
I had been doing this with a log4j init servlet for a while now, and was just putting up with the logging not working until the app got booted up, it was just not obvious to me that this should be in a context listener.
but now here is it in a servlet context listener. It is all jndi and log4j api stuff, so was pretty quick to move over.
to make this work in tomcat, i add the following to the web.xml:
and to the META-INF/context.xml file, for tomcat to auto map JNDI resorces on deployment of a war:
and in the tomcat instance's server.xml:
where the value of the environment variable (file:/...) is the full property path to the log4j initialization file, outside of your web application. For me, this is also my system configuration for the tomcat instance folder.