参考:http://blog.csdn.net/arkblue/article/details/7772971
更详细的参考 :http://www.bkjia.com/ASPjc/929906.html
归档日志,保存最新的日志到,gps-1.log、gps-2.log、gps-3.log、文件中(设置归档为归档文件后,不需再设maxHistory)
<configuration scan="true" scanPeriod="30 seconds">
<appender name="ROLLING"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/gps.log</file>
<!-- 首先向这个文件(log/gps.log)中输出日志 ,如果这个文件 maxFileSize 到 1MB了,生成第一个归档文件(可压缩) log/gps-%minIndex.log,直到生成 maxIndex.log文件
后,重复向log/gps-%minIndex.log输出,覆盖之前的日志 ,可以通过改变maxFileSize和maxIndex来保证最新归档日志的数量 -->
<!-- 滚动策略, -->
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>log/gps-%i.log</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>3</maxIndex><!-- 最多归文件数 -->
</rollingPolicy>
<!-- 控制触发策略 -->
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>1MB</maxFileSize>
</triggeringPolicy>
<encoder>
<pattern>%date %level %class{0}#%method [%file:%line] %msg%n
</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%file:%line] %msg%n</pattern>
</encoder>
</appender>
<root level="error">
<appender-ref ref="STDOUT" />
<appender-ref ref="ROLLING" />
</root>
</configuration>
*******************************************************************
另一种 使用maxHistory最大保留天数设置,超过此时间的删除
<configuration scan="true" scanPeriod="30 seconds">
<appender name="ROLLING"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<prudent>true</prudent>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log/dal-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>30</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>10MB</maxFileSize>
<maxHistory>100</maxHistory>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%date %level %class{0}#%method [%file:%line] %msg%n
</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %level %class{0}#%method [%file:%line] %msg%n
</pattern>
</encoder>
</appender>
<logger name="com.lc.da.acceptor" level="info" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<logger name="com.lc.da.connector.mm" level="info" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<logger name="com.lc.da.webService" level="error" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<logger name="com.lc.da.rmi" level="error" additivity="false">
<appender-ref ref="STDOUT" />
</logger>
<root level="error">
<appender-ref ref="STDOUT" />
<appender-ref ref="ROLLING" />
</root>
</configuration>
详细的参见:http://www.bkjia.com/ASPjc/929906.html