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.
Rich Seller Aug 10 '09 at 19:57 2009-08-10 19:57
source share