Are there any reasons to use XML over properties files for Log4J configuration?
Properties can be defined by a properties file or by an XML file. Log4j looks for a file named log4j. xml and then for a file named log4j. properties.
Use this simple log4j2. xml for quick reference to log statements in multiple log files. This configuration logs different levels of logs ( debug , info etc.) to different files, using LevelRangeFilter , so that our logs are clean and separated for easy debugging and reporting purposes.
During Content Engine installation, two log4j sample files are placed on the system in the ContentEngine\config\samples\ folder: log4j. properties. client: A Java format file that contains client configuration settings.
log4j has three main components: loggers: Responsible for capturing logging information. appenders: Responsible for publishing logging information to various preferred destinations. layouts: Responsible for formatting logging information in different styles.
There's an interesting discussion on the merits of both in this blog. The section below is a quote from that blog:
Properties can be defined by a properties file or by an XML file. Log4j looks for a file named log4j.xml and then for a file named log4j.properties. Both must be placed in the src folder.
The property file is less verbose than an XML file. The XML requires the log4j.dtd to be placed in the source folder as well. The XML requires a dom4j.jar which might not be included in older Java versions.
The properties file does not support some advanced configuration options like Filters, custom ErrorHandlers and a special type of appenders, i.e. AsyncAppender. ErrorHandlers defines how errors in log4j itself are handled, for example badly configured appenders. Filters are more interesting. From the available filters, I think that the level range filter is really missing for property files.
This filter allows to define that a[n] appender should receive log messages from Level INFO to WARN. This allows to split log messages across different logfiles. One for DEBUGGING messages, another for warnings, ...
The property appender only supports a minimum level. If you set it do INFO, you will receive WARN, ERROR and FATAL messages as well.
To address the comments on my original answer: The italics are my emphasis. For the purposes of the tutorial the author has chosen to gloss over, or unintentionally omitted that the properties or xml need only be on the classpath rather than needing to be in the src folder. A simple way to add them to the classpath is to add them to the src folder, so for the purpose of the tutorial that was obviously deemed sufficient.
None of this is directly relevant to the question asked or the intention of the answer, which is to discuss the merits or otherwise of using xml files to configure log4j. I consider that the rest of the quote is relevant and useful to those looking to make an informed choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With