aspose file tools*
The moose likes Other Open Source Projects and the fly likes where to put log4j.properties? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "where to put log4j.properties?" Watch "where to put log4j.properties?" New topic
Author

where to put log4j.properties?

C Rakesh
Greenhorn

Joined: May 04, 2009
Posts: 18
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.

SCJP 5.0, Preparing for SCWCD
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Try in just WEB-INF as opposed to WEB-INF/classes


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
C Rakesh
Greenhorn

Joined: May 04, 2009
Posts: 18
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

Where does PropertyConfigurator.configure("log4j.properties"); look for the file...? The CLASSPATH?
C Rakesh
Greenhorn

Joined: May 04, 2009
Posts: 18
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

Joined: Jun 24, 2003
Posts: 3274
    
    5

I have to admit I'm stuck, I can't see anything you're doing wrong I'm afraid
Freddy Wong
Ranch Hand

Joined: Sep 11, 2006
Posts: 959

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.



SCJP 5.0, SCWCD 1.4, SCBCD 1.3, SCDJWS 1.4
My Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: where to put log4j.properties?