• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where to put log4j.properties?

 
C Rakesh
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to develop a simple web application and I want to configure log4j In tomcat, I have put my log4j.properties inside WEB-INF\classes. In my servlet I am using the code

PropertyConfigurator.configure("log4j.properties");

to read the properties file.

I have done the above steps according to log4j tutorial. But I am getting the error



Please guide me to resolve this issue.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try in just WEB-INF as opposed to WEB-INF/classes
 
C Rakesh
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martijn Verburg wrote:Try in just WEB-INF as opposed to WEB-INF/classes


I have tried the same. I am getting the same error.

Thanks for the response.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where does PropertyConfigurator.configure("log4j.properties"); look for the file...? The CLASSPATH?
 
C Rakesh
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Martijn Verburg wrote:Where does PropertyConfigurator.configure("log4j.properties"); look for the file...? The CLASSPATH?


Actually I am not very sure. I read from some docs that PropertyConfigurer will look for for the file in the CLASSPATH.
But I didn't tried to set the properties file in the CLASSPATH. That is one of the two methods, if I am right. I am following the second approach, putting the properties file inside WEB-INF/classes and PropertyConfigurer can find that without any extra code.

Anyway, I am sure that PropertyConfigurator.configure is not looking for the file in the root of the web app.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to admit I'm stuck, I can't see anything you're doing wrong I'm afraid
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you put your log4.properties in the WEB-INF/classes, log4j will read it automatically.

In case you need to tell where the log4j.properties programmatically. You can try this.

Try it in the ServletContextListener or Servlet and see if it works.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic