Hi - I'm not sure if this is the correct place to ask, but here goes:
I'm using log4j for logging from my servlet. At present, I have the log4j.properties file located in WEB-INF\classes so that it can be found on the classpath. Unfortunately, it contains paths to the log files, and the app is deployed as a war file, so changing the locations involves rebuilding it...
There's a similar issue with web.xml - it's built into the war file, so changing anything deployment wise means rebuilding the app. This strikes me as mad - am I being dumb and missing something? I thought the whole point was to allow configuration of stuff like this to be done without needing to rebuild?
If you look at the log4j docs, you can find something called SetupServlet in a nutshell is a servlet that is checking for changes in the configuration if such happen then it reloads the configuration and applies it run time.
She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
Joined: Mar 20, 2005
Thanks Jim - that helps somewhat - let me see if I've got this right...
I should write a second servlet called for example SetupServlet in whose init method I read an initParameter which specifies where the log4j properties file is located on the filesystem. Having done that, I can set up log4j using a PropertyConfigurator. I need to specify that this servlet is to be loaded by the JVM first by giving it a load-on-startup value smaller than the first servlet.
The point of doing this is so that I'm not dependent on the properties file being on the classpath. This in turn means I can move the log4j properties out of the application war file back into the general filesystem so that changes don't require the war file being rebuilt.
Is that about right?
You mentioned that the servlet could check for changes in the configuration file and apply them at runtime - I've no idea how I'd do that. Any clues? At the moment I think I'd have to restart the container, which would obviously boot everyone out of the application.