Menu

Thursday, July 7, 2011

Log4j - Rolling File Appender

Rolling File Appender in log4j.properties
  • 01.log4j.appender.rolling=org.apache.log4j.RollingFileAppender
  • 02.log4j.appender.rolling.File=C://rolling.log
  • 03.log4j.appender.rolling.MaxFileSize=5KB
  • 04.log4j.appender.rolling.MaxBackupIndex=1
  • 05.log4j.appender.rolling.layout=org.apache.log4j.PatternLayout
  • 06.log4j.appender.rolling.layout.ConversionPattern=%d [%t] %-2p %c -%m%n

Rolling File Appender in log4j.xml


  • 01. <?xml version="1.0" encoding="UTF-8" ?>
  • 02. <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
  • 03. 
  • 04. <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  • 05.        <!-- File Appender -->
  • 06.     <appender name="rolling" class="org.apache.log4j.RollingFileAppender">
  • 07.         <param name="File" value="log/rolling.log"/>
  • 08.         <param name="MaxFileSize" value="1kb"/>
  • 09.         <param name="MaxBackupIndex" value="1"/>
  • 10.         <param name="Append" value="true"/>
  • 11.         <layout class="org.apache.log4j.PatternLayout">
  • 12.             <param name="ConversionPattern" value="%-5p%c{1}-%m%n"/>
  • 13.         </layout>
  • 14.     </appender>
  • 15. 
  • 16.    <root>
  • 17.         <priority value ="debug"/>
  • 18.         <appender-ref ref="rolling"/>
  • 19.     </root>
  • 20. </log4j:configuration>