This is not pointing where you think it is. Try a solution that provides the filename only and use the application context or ClassLoader to find the file.
Yes I know I've this solution and that works fine! But my need is to have 3 or more properties files for my different environments (dev, prod, test, ...)
The solution I've found is to install my log4j files into the conf directory into tomcat 5
So I'd like to configure my webapp with log4j with a property file independent of the deployment
Try a solution that provides the filename only and use the application context or ClassLoader to find the file.
1) Use the web.xml init setting to define the different files via conguration (use the file name, no '..', no slashes) 2) Place the file in the WEB-INF directory (so it is off the web-app classpath) 3) Check the ServletContext API and use getResource to find a URL to the file (use the value directly from the init parameters) 4) Pass this to the PropertyConfigurator as a URL
This may not be exactly right, but it should work overall and it should work for your requirements. The other way is to allow the file to be loaded from the web app classpath and just place other values earlier on the classpath, then they will be picked up earlier.
S�bastien Bervoets
Greenhorn
Joined: Oct 14, 2005
Posts: 5
posted
0
I finally found a solution :
InitServlet.class
web.xml
log4j.properties
Now I try to use a xml format for the log4j config file.
And then the code should be (I think) :
Unfortunatly this code doesn't work. I'm working with Tomcat 5.0.28 (configured with a xml file for log4j logging), log4j-1.2.12, JDK 1.4.2_09
Somebody have an idea ?
PS : Thank to David and Ben for their help
Neeraj Dheer
Ranch Hand
Joined: Mar 30, 2005
Posts: 225
posted
0
For using xml property files in log4j, instead of calling PropertyConfigurator.configurer(), call DOMConfigurator.configurer()