logback RollingFileAppender不滚动文件

时间:2017-08-18 12:12:35

标签: java logging logback rollingfileappender

我有一个带有SizeAndTimeBasedRollingPolicy的RollingFileAppender appender的logback配置。但是,似乎每当我的应用程序运行时,logback都不会滚动文件并且会一遍又一遍地追加到同一个文件。

我的应用程序执行一段时间不超过几秒钟。我认为这将是问题所以我甚至使用了cleanHistoryOnStart选项,但即使这样也行不通。请帮帮我。

这是配置

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="20 seconds">
  <appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>[%d{yyyy-MM-dd HH:mm:ss}] :: %-5p :: %-10class{0}:%L - %m%n</pattern>
    </encoder>
  </appender>
  <appender name="processLogFileAppender"  class="ch.qos.logback.core.rolling.RollingFileAppender">
        <append>true</append>
        <file>/home/elkapp/ETL_Logs/ETLLogsGenerator/logs/ETLLogsGenerator.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
                <fileNamePattern>/home/elkapp/ETL_Logs/ETLLogsGenerator/logs/ETLLogsGenerator-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
                <maxHistory>30</maxHistory>
                <maxFileSize>10MB</maxFileSize>
                <totalSizeCap>500MB</totalSizeCap>
                <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
                <pattern>[%d{yyyy-MM-dd HH:mm:ss}] :: %-5p :: %-10class{0}:%L - %m%n            </pattern>
        </encoder>
  </appender>

  <logger name="com.ibm.etllogsgenerator" level="INFO">
    <appender-ref ref="processLogFileAppender"/>
    <!--appender-ref ref="consoleAppender"/-->
  </logger>

</configuration>

1 个答案:

答案 0 :(得分:0)

将政策更改为

class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"

您可以看到示例here