You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Ceki Gülcü <ce...@qos.ch> on 2003/02/18 22:43:45 UTC
EntityResolver code+DTD issues
Interestingly enough, the Log4jEntityResolver code as proposed in 1.2.8
(not yet released) does not work with the XML parser that ships in JDK 1.4
although it works fine with xerces.
Trying to parse the following config file with DOMConfigurator and the JDK
1.4 XML parser will barf:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
...
</log4j:configuration>
For example:
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 resources to perform automatic configuration.
log4j: System property [javax.xml.parsers.DocumentBuilderFactory] is :null
log4j: Standard DocumentBuilderFactory search succeded.
log4j: DocumentBuilderFactory is:
org.apache.crimson.jaxp.DocumentBuilderFactoryImpl
log4j:ERROR Parsing error on line 2 and column -1
log4j:ERROR Relative URI "log4j.dtd"; can not be resolved without a base URI.
log4j:ERROR Could not parse input source [org.xml.sax.InputSource@1abab88].
org.xml.sax.SAXParseException: Relative URI "log4j.dtd"; can not be
resolved without a base URI.
at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)
at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3176)
at org.apache.crimson.parser.Parser2.resolveURI(Parser2.java:2758)
at
org.apache.crimson.parser.Parser2.maybeExternalID(Parser2.java:2730)
at
org.apache.crimson.parser.Parser2.maybeDoctypeDecl(Parser2.java:1129)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:489)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
at
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at
org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(Unknown Source)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(Unknown Source)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(Unknown Source)
at org.apache.log4j.xml.DOMConfigurator.configure(Unknown Source)
at chapter3.MyApp3.main(MyApp3.java:13)
log4j:WARN No appenders could be found for logger (chapter3.MyApp3).
log4j:WARN Please initialize the log4j system properly.
Changing SYSTEM "log4j.dtd" to SYSTEM "file://log4j.dtd" will work:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "file://log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>
...
</log4j:configuration>
Xerces will work with both files. The problem occurs only with the XML
parser in JDK 1.4 and 1.2.8 (proposed).
One solution is to support public DTD, as in
<!DOCTYPE log4j:configuration PUBLIC
"-//Apache Software Foundation//DTD Log4j Configuration 1.2//EN"
"http://jakarta.apache.org/log4j/dtds/log4j_1_2.dtd">
The entity resolver to support the above is trivial to write (thanks to
Tomasz Stanczak). The problem with this approach is that existing config
files would need to be modified which quite unacceptable.
It's pretty complicated...
--
Ceki
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org
Re: EntityResolver code+DTD issues
Posted by Mauro Talevi <ma...@aquilonia.org>.
Ceki,
on a related point:
DOMConfigurator has a
doConfigure( Element, LoggerRepository )
method, but if you parse the Element using a JAXP parser ( say xerces )
without specifying the EntityResolver and pass it to the method it will
complain about not finding the dtd (I'm using JDK1.4)
It on the other hand one specifies the Log4jEntityResolver as the
EntityResolver in the DocumentBuilder (as is done in the
doConfigure ( InputSource, LoggerRepository ) method) and passes the
parsed Element to the doConfigure( Element, LoggerRepository ) method
then it works fine.
Since the EntityResolver cannot be specified in the Element, I would
suggest adding a new method
doConfigure( Element, EntityResolver, LoggerRepository)
(and an equivalent static method perhaps)
that checks that the EntityResolver is the the correct one.
It would clearly suggest to the user that the EntityResolver - the same
one that the was specified in the DocumentBuilder - is needed.
If null is passed a warning should be outputted.
I would then make doConfigure( Element, LoggerRepository) use this new
method with null EntityResolver.
Have I overlooked something or is there a simpler way to use the
configurator via an Element?
Cheers, Mauro
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org