File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Log4j Properties not loaded Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Log4j Properties not loaded" Watch "Log4j Properties not loaded" New topic
Author

Log4j Properties not loaded

M Mehta
Ranch Hand

Joined: Aug 03, 2006
Posts: 82
I am working on a web application and trying to use log4j logging in it. But I am not able to load the log.properties file.
I am using PropertyConfigurator.configure("log.properties"); where log.properties is in classpath. But it gives me in following exception:




However if I try to use the same thing from a stand alone application with main , it works fine.
Can anyone help me know the issue?

Thanks,
Me
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

PropertyConfigurator.configure(String) uses local files to load from. Try using Class.getResource or ClassLoader.getResource in combination with PropertyConfigurator.configure(URL):
The actual path to the resource may need to be a little different, but this would be the basic idea.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Raj Kamal
Ranch Hand

Joined: Mar 02, 2005
Posts: 400
Hi,

The first line in the log says

ERROR Could not read configuration file [log.properties].


Since you are working on a web app the properties has to be in the WEB-INF/classes folder of your web application.

Cheers,
Raj.
M Mehta
Ranch Hand

Joined: Aug 03, 2006
Posts: 82
yeah, I put it in the WEB-INF/classes, but still getting the same error.
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

Have you tried my advice already?
 
 
subject: Log4j Properties not loaded
 
Threads others viewed
Calling webMethods from Java - 401 Unauthorized
DB initialization failure error in application
unable see the server logs in console of websphere 6.0
Hibernate in RAD 7 on WAS 6.1 server. getting asm.jar related error
getting the Duplicate home name Exception while installing application

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture