File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j.properties not found

 
Rich Smyth
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get my Java app to use log4j. I've stored my log4j.properties
file in the same directory as my TestLogging.class file but Log4j does not find the properties file there. What did I do wrong?
When I run my program I get these messages:
log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@12f6684.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@12f6684 class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@12f6684.
log4j: Trying to find [log4j.properties] using sun.misc.Launcher$AppClassLoader@12f6684 class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [null].
log4j:WARN No appenders could be found for logger (logging.TestLogging).
log4j:WARN Please initialize the log4j system properly.
thanks for any clues,
Rich Smyth.
 
Chad Dalton
Greenhorn
Posts: 20
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a servlet?
If so you need a class to configure log4j for the context

http://logging.apache.org/log4j/docs/manual.html
That above assumes you have a servlet level variable defined in your web.xml called log4j-init-file and it points to your .properties (or xml) file relative to the server's path. Initing via standalong is quite similar.
There are a ton of examples on that page above that should get you going. Pick the one that is closest to your implementation and let us know where you are having problems.
-c
[ March 29, 2004: Message edited by: Chad Dalton ]
 
Rich Smyth
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The tutorial I'm following has the instruction: "Save the following lines in a file named log4j.properties in the same directory as TestLogging.class "
I blindy did as instructed. My mistake. I should have noticed that this only works if TestLogging is in the default package. I stored the class in logging.TestLogging so the properties file was not at the root directory.
Thanks for the link Chad. I'm currently learning from http://www.vipan.com/htdocs/log4jhelp.html, which I find very well done.
Rich
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic