tags:

views:

37

answers:

2

I'd like to make a log4j output file that is XML and give it a root element. Hence, I'd like it to start with a tag and end with a tag.

What do I put in my log4j.xml to make this happen?

Right now, all I have is this:

 <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
  <param name="File" value="logs/file.log" />
  <param name="Append" value="false" />
  <param name="MaxFileSize" value="5000KB" />
  <layout class="org.apache.log4j.PatternLayout">
   <param name="ConversionPattern" value="%m%n" />
  </layout>
 </appender>
A: 

Change that PatternLayout to an org.apache.log4j.xml.XMLLayout.

Nick Dixon
A: 

Have a look at the api of XMLLayout:

http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/XMLLayout.html

It clearly explains that you need to include the resulting xml output within another document (by using xml entity). So in your parent document you can place a root element of your choice.

This will also allow you to use chain saw.

Yoni