• Post Reply Bookmark Topic Watch Topic
  • New Topic

Log4j Properties not loaded

 
M Mehta
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rajkamal Pillai
Ranch Hand
Posts: 445
1
Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, I put it in the WEB-INF/classes, but still getting the same error.
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried my advice already?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!