0

DailyRollingFileAppender can be used to generate new log files daily.RollingFileAppender has the implementation to create new log files when the size of the file exceeds a given value.However I need to implement both of these together using log4j.

This is the XML configuration file I've used to generate daily logs.How can I modify it to include the maxsize also??

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
                 xmlns:log4j='http://jakarta.apache.org/log4j/'>

<appender name="fileAppender1" class="org.apache.log4j.DailyRollingFileAppender">
  <param name="append" value="true"/>
  <param name="file" value="D:/calculator/logs/log"/>
  <param name="DatePattern" value="'_'yyyy-MM-dd" />
  <param name="immediateFlush" value="true"/>
   <param name="threshold" value="info"/>
  <layout class="org.apache.log4j.PatternLayout">
     <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n%n"/>
  </layout>
</appender>

<root>
    <priority value="info"></priority>
    <appender-ref ref="fileAppender1" />
      </root>


</log4j:configuration>
  • 1
    possible duplicate of [How do you get log4j to roll files based on date and size?](http://stackoverflow.com/questions/794987/how-do-you-get-log4j-to-roll-files-based-on-date-and-size) – Morfic May 05 '14 at 07:05

1 Answers1

0

If you want to roll a file after reaches 100KB (e.g.), try to add:

 <param name="MaxFileSize" value="100KB"/>
Tonino
  • 1,137
  • 10
  • 25
  • I tried that but a Warning message is being displayed `log4j:WARN No such property [maxFileSize] in org.apache.log4j.DailyRollingFileAppender.` – user2806 May 05 '14 at 07:10
  • That won't work because he's using a `DailyRollingFileAppender`. A manually implemented cross feature between that and the `RollingFileAppender` should do the trick – Morfic May 05 '14 at 07:13