• 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

log4j - error loading log4j.dtd

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I am using log4j 1.2.11.
I have a log4j.xml with following declaration

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

When I load the application containing above log4j.xml file in websphere environment, it looks for the DTD under C:\WebSpherev6\AppServer\bin. Why does this happen? Is it because SYSTEM?
Is there any way I can point the app to load the dtd from the root of my application?
I have a FileAppender

<appender name="A1" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="Project_ERROR.log">
...

and the log file created through this appender also goes under above \bin directory, even if I give an absolute path (C:\xx.log or give relative path xx.log, the end result is the same, log file under \bin directory. Is there any way I can specify my own log directory?

Thanks in advance.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally when an XML parser is told to load a DTD like that, it will look in the same directory as the XML file that contains that line. But if the parser cannot tell where it loaded the XML file from, it falls back to looking in the current working directory. So you should look at the place where you parse the XML file, and change it so that the parser can tell where the XML file is located.

As for your file appenders, they will put the file in the current working directory if you specify a relative path. What else could they do? Specify an absolute path for your files. (I know you said you did that. I believe you were confused and didn't really do it.)
 
nilesh shah
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

Thanks for the quick response.

For the first part, I have log4j.xml location in web.xml and I am using following code in the listener to load the xml

String log4jConfigLocation = context.getInitParameter("log4j.configuration");
URL log4JConfigURL = context.getResource(log4jConfigLocation);
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(log4JConfigURL.openStream());
DOMConfigurator conf = new DOMConfigurator();
conf.doConfigure(doc.getDocumentElement(), hierarchy);

and I do have my DTD in the root of my web app where log4j.xml also resides. Then why would it look for dtd under \websphere6\appserver\bin?

The same thing with appender, the issue is it doesn't write the log file under my web app root directory but under \websphere6\appserver\bin ??
Thanks in advance again.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because when you pass an input stream to the parser, the parser has no idea of the URL it came from and can't find out. Try passing it the URL:For the appenders, as I already said, you have to use an absolute path and not a relative path.
 
nilesh shah
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

Thanks a bunch!! Your first suggestion is working fine, my DTD issue has been resolved.

Nilesh
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic