• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

where to put log4j.properties?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try in just WEB-INF as opposed to WEB-INF/classes
 
C Rakesh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where does PropertyConfigurator.configure("log4j.properties"); look for the file...? The CLASSPATH?
 
C Rakesh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to admit I'm stuck, I can't see anything you're doing wrong I'm afraid
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic