my dog learned polymorphism
The moose likes Other Open Source Projects and the fly likes log4j - error loading log4j.dtd Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Reply Bookmark "log4j - error loading log4j.dtd" Watch "log4j - error loading log4j.dtd" New topic
Author

log4j - error loading log4j.dtd

nilesh shah
Greenhorn

Joined: May 25, 2006
Posts: 10
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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

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

Joined: May 25, 2006
Posts: 10
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
Bartender

Joined: Oct 14, 2005
Posts: 16483
    
    2

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

Joined: May 25, 2006
Posts: 10
Paul,

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

Nilesh
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: log4j - error loading log4j.dtd
 
Similar Threads
log4j.xml No appenders could be found for logger()
log4j separate file logging problem
log4j: Why aren't my debug statements showing?
Log4j Console Output
Where are my log4j logs getting written to?