Why choose XML property files for your Log4J configuration?

Are there any reasons to use XML property files to configure Log4J?

+42
java xml logging log4j
Aug 10 '09 at 19:46
source share
4 answers

There is an interesting discussion about the merits of both on this blog . The following is a quote from this blog:

Properties can be defined by a property file or an XML file. Log4j looks for a file called log4j.xml, and then for a file called log4j.properties. Both should be placed in the src folder.

The property file is less verbose than the XML file. XML requires log4j.dtd to be placed in the source folder. XML requires dom4j.jar, which cannot be included in older versions of Java.

The properties file does not support some additional configuration parameters, such as filters, custom ErrorHandlers, and a special type of additives, that is, AsyncAppender. ErrorHandlers determines how errors are handled in log4j, such as poorly configured applications. Filters are more interesting. From the available filters, I believe that the level property filter is really absent for property files.

This filter allows you to determine that [n] appender should receive log messages from INFO to WARN. This allows you to split log messages into different log files. One for DEBUGGING messages, another for warnings, ...

The appender property supports only the minimum level. If you set it to INFO, you will also receive WARN, ERROR, and FATAL messages.




To answer the comments on my original answer: italics mine. For the purpose of the tutorial, the author decided to hush up or inadvertently skip that properties or xml should only be in the class path, and not in the src folder. An easy way to add them to the class path is to add them to the src folder, so for the purposes of the tutorial, which was clearly considered sufficient.

None of this is directly related to the question asked or the intention of the answer, namely to discuss the merits or otherwise use xml files to configure log4j. I believe that the rest of the quote is relevant and useful to those who want to make an informed choice.

+39
Aug 10 '09 at 19:57
source share
β€” -

log4j is gradually moving to XML, so properties are an obsolete format.

Some new features can only be configured in XML. I was forced to switch to XMl because I need to use TimeBasedRollingPolicy.

However, XML is so detailed. I still use properties when I can.

+9
Aug 10 '09 at 19:56
source share

Well, one thing that you can only do in the xml configuration is to configure the logger to use buffering (using org.apache.log4j.AsyncAppender).

However, if you require more functionality, you may also need to look at the log, which contains a number of other improvements over log4j.

+3
Aug 10 '09 at 19:54
source share

Perf4j ( http://perf4j.codehaus.org ) is a very good performance monitoring system that is configured next to log4j and works with it and requires log4j.xml files.
So, if you plan to use perf4j (I would recommend), then an XML format is required.

+3
Dec 21 '09 at 15:01
source share



All Articles