Log4j Properties VS XML IDE autocompletion and code assistance

Here’s why I prefer Log4j configured via an XML rather than a properties file:

I love my IDEs and a good reason for that is their autocompletion capabilities. XML structured configuration files tend to give you their grammar/syntax/doc and rules on an XSD or DTD file that are publicly available to help IDEs (and patient humans) autocomplete while editing the XML file.

I personally highly value this convenience.

Now for some reason everywhere in the Internet when I query “log4j xml file” I get back lots of sample config files that they all start by:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

This simply doesn’t work and doesn’t help the IDE (let it be IntelliJ or Eclipse) that is looking in vain for guidance and instructions out of a missing log4j.dtd file (found under org.apache.log4j.xml) or a meaningful http://jakarta.apache.org/log4j/ url.

To keep the IDE happy replace with the url of the DTD and remove the latter url (log4j:configuration is defined in the DTD file anyway therefore keeping happy the IDEs autocompletion system).

<?xml version="1.0" encoding="UTF-8" ?>
                <!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
        <log4j:configuration>
Advertisements