• 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

initializing log4j

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this question is asked many times but I can't get a handle on this . . . I am trying to load the file "A3-log4j.xml" as below:

String path = "A3-log4j.xml";
DOMConfigurator.configure(path);


My file is in /WEB-INF/classes where it should be and other classes are loading correctly. Why do I get FileNotFoundExceptions here? (Yes, I want to use DOMConfigurator so my app is portable).
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String path = "A3-log4j.xml";


This says that the file is in the current working directory, which, chances are, isn't your WEB-INF/classes directory.

I don't explicitly initialize log4j.
I just put the config files in that directory and let it find them on it's own by traversing the classpath.

If you need to initialize it yourself, look at either getRealPath (which sometimes will return the path of a resource within your web app) or, better, look into getResourceAsStream and learn how to stream the file to log4j.
 
John Eric Hamacher
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I accomplished loading the file by:

URL url = context.getResource("/WEB-INF/config/A3-log4j.xml");
DOMConfigurator.configure(url);

I know the file has loaded because I get warnings about invalid parameters to RollingFileAppender. Thanks.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic