wood burning stoves 2.0*
The moose likes Servlets and the fly likes log4j... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "log4j..." Watch "log4j..." New topic
Author

log4j...

S�bastien Bervoets
Greenhorn

Joined: Oct 14, 2005
Posts: 5
Hi all,

I'm new and I've already a problem with log4j.

Here my implementation of log4j :

[h1]be.arista.Oscar.servlet.OscarServletContextListener[/h1]


[h1]web.xml[/h1]


[h1]log4jOscar.properties[/h1]


My problem is that nothing appens. What's wrong ?

Thank you so much

[Edit to break long line]
[ October 15, 2005: Message edited by: David O'Meara ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459


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.
S�bastien Bervoets
Greenhorn

Joined: Oct 14, 2005
Posts: 5
I've tried to put the path directly like this :

PropertyConfigurator.configure("c:\\temp\\log4jOscar.properties");

but nothing better
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I put log4j.properties in my classes directory (to get it on the classpath) and log4j finds it without a problem.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
S�bastien Bervoets
Greenhorn

Joined: Oct 14, 2005
Posts: 5
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

Do you have an idea ?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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
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
For using xml property files in log4j, instead of calling
PropertyConfigurator.configurer(), call DOMConfigurator.configurer()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log4j...