Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j.properties vs log4j.xml

Tags:

log4j

I was asked to move from properties style configuration to xml style. The process itself is straightforward and it is not causing me any trouble, I was simply curious why I got asked this and I looked for the reason. I found this nice post Why chose XML over properties files for Log4J configuration? (more than 3 years old but still the most informative I could find), which was pointing pointing to this even older tutorial. They state

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.

I checked it out and, contrary to the statement, found out that Log4j looks first for the properties file and in a second time for xml. In fact, if I keep both in the same folder, the output is formatted according to the properties file. So, am I misunderstood the statement? Is it simply wrong? The statement has been made for log4j 1.2.14 while I am on log4j 1.2.17, is it possible the log4j team changed the priority? I couldn't find any related documentation, but it will be a strange trend inversion since the xml looked to be the preferred way to configure log4j

like image 458
ThanksForAllTheFish Avatar asked Jan 24 '13 09:01

ThanksForAllTheFish


People also ask

What is the difference between log4j xml and log4j properties?

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.

What is log4j xml?

xml configuration or using log4j. This is the main configuration file having all runtime configurations used by log4j. This file will contain log4j appenders information, log level information and output file names for file appenders.

Where does log4j xml go?

Locate the log4j. xml file under the oarm/WEB-INF/classes/ directory. Update the log output path for each appender.


1 Answers

Have a look at the JavaDoc. The documentation of the PropertyConfiguratorClass (log4j.properties) points out that

The PropertyConfigurator does not handle the advanced configuration features supported by the DOMConfigurator such as support custom ErrorHandlers, nested appenders such as the AsyncAppender, etc.

So the DOMConfigurator (log4j.xml) offers advanced options.

Beside that you can have (at least a simple) validity check of log4j.xml files using the provided log4j.dtd.

If youd do not make use of the advanced features it is needless to change from properties to xml files.

What you really should think about is to change from log4j to log4j 2 beta or even slf4j. Development of log4j has stopped and the founder of it (@Ceki) invented slf4j.

like image 132
FrVaBe Avatar answered Oct 01 '22 23:10

FrVaBe