logback 设置日志保留天数



  <appender name="FILEALL" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${LOG_DIR}/logistic-web.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>${LOG_DIR}/logistic-web-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
      <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
        <maxFileSize>30MB</maxFileSize>
      </timeBasedFileNamingAndTriggeringPolicy>
      <!-- keep X days' worth of history -->
      <maxHistory>${LOG_HIS_MAX}</maxHistory>
      <cleanHistoryOnStart>true</cleanHistoryOnStart>
    </rollingPolicy>
    <append>true</append>
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{45} - %msg%n</pattern>
      <charset>utf-8</charset>
    </encoder>
  </appender>

  <!--导入外部配置-->
  <include file="/opt/incito/conf/logback-inc.xml"/>

logback-inc.xml : 

<included>

  <!--
  开发时,如果此文件不存在,所有变量均使用 DEBUG level,
  日志文件会在tomcat/bin/中
  -->

  <!--日志存储目录-->
  <property name="LOG_DIR" value="/var/log/incito/" />
  <!--保留多少天的日志-->
  <property name="LOG_HIS_MAX" value="100" />

  <!--standard out,只在开发dev时使用 其它环境均关闭-->
  <property name="STDOUT_LOG_LEVEL" value="OFF" />

  <!--日志级别设置-->
  <property name="LOG_LEVEL_APP" value="DEBUG" />
  <property name="LOG_LEVEL_JDBC" value="INFO" />


  <!--开发环境配置示例(把下方注释放开,默认会覆盖上方属性) -->
  <!--
  <property name="LOG_DIR" value="/var/log/incito/" />
  <property name="LOG_HIS_MAX" value="1" />
  <property name="STDOUT_LOG_LEVEL" value="DEBUG" />
  <property name="LOG_LEVEL_APP" value="DEBUG" />
  <property name="LOG_LEVEL_JDBC" value="DEBUG" />
  -->


</included>


abstract public class DefaultArchiveRemover extends ContextAwareBase implements
        ArchiveRemover {

  static protected final long UNINITIALIZED = -1;
  // aim for 64 days, except in case of hourly rollover
  static protected final long INACTIVITY_TOLERANCE_IN_MILLIS = 64L * (long) CoreConstants.MILLIS_IN_ONE_DAY; // 默认删除的范围是64天以内,所以如果存在64天以前的文件,不管如何设置最大保留天数,这些文件也不会被删除

注意常量: 

ch.qos.logback.core.rolling.helper.DefaultArchiveRemover.INACTIVITY_TOLERANCE_IN_MILLIS

默认删除的范围是64天以内,所以如果存在64天以前的文件,不管如何设置最大保留天数,这些文件也不会被删除



你可能感兴趣的:(logback)