Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j...

 
S�bastien Bervoets
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried to put the path directly like this :

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

but nothing better
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put log4j.properties in my classes directory (to get it on the classpath) and log4j finds it without a problem.
 
S�bastien Bervoets
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For using xml property files in log4j, instead of calling
PropertyConfigurator.configurer(), call DOMConfigurator.configurer()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic