Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1190

Unexpected rolling of log files while using RollingFileAppender with FixedWindowRollingPolicy and SizeBasedTriggeringPolicy

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.1.7
    • logback-core
    • None
    • CentOS
      Linux 2.6.32-504.8.1.el6.x86_64 x86_64 GNU/Linux

    Description

      The application log file is getting rotated "on the hour" even thought it's size is less that the sepicified maxFileSize=500MB. Trailing integer indexes are being added irrespective of the specified "fileNamePattern" and these file never get cleaned up. There are also some zero byte files created. This rolling only seems to be happening "on the hour".

      Rolling happens as expected between the hours when the file size reaches 500MB. Also, there seems to be an arbitrary limit around 100MB. For instance, if the maxFileSize is set to 100MB, this rolling of files on the hour never happens and the behavior is as expected.

      Below is the logback configuration and the log file listings:
      logback.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      
      <configuration scan="true" scanPeriod="60 seconds">
      
        <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
          <file>${catalina.base}/logs/pas.log</file>
          <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <fileNamePattern>${catalina.base}/logs/pas.%i.log</fileNamePattern>
            <minIndex>1</minIndex>
            <maxIndex>1</maxIndex>
          </rollingPolicy>
          <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <maxFileSize>500MB</maxFileSize>
          </triggeringPolicy>
          <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
            </Pattern>
          </layout>
        </appender>
      
        <!-- appender to send logs to ELK -->
        <appender name="LOGSTASH_AGENT" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
            <destination>127.0.0.1:4560</destination>
            <encoder class="net.logstash.logback.encoder.LogstashEncoder" />
        </appender>
      
        <!-- limit level of logging -->
        <logger name="org.apache.cxf.interceptor" level="INFO" />
        <logger name="org.apache.cxf.services" level="WARN" />
        <logger name="org.apache.cxf" level="WARN" />
        <logger name="org.apache.camel.component.log" level="INFO" />
        <logger name="org.apache.camel" level="WARN" />
        <logger name="org.apache.zookeeper" level="WARN" />
        <logger name="org.apache.curator" level="WARN" />
        <logger name="org.apache.http" level="WARN" />
        <logger name="net.sf.ehcache" level="WARN" />
        <logger name="org.springframework" level="WARN" />
      
      
        <root level="INFO">
          <appender-ref ref="LOGSTASH_AGENT" />
          <appender-ref ref="FILE" />
        </root>
      </configuration>
      

      file listings:

      >ls -ltr
      -rw-r--r-- 1 app app 524735205 Jun  3 15:38 pas.1.log
      -rw-r--r-- 1 app app 144538596 Jun  3 15:39 pas.log
      
      >ls -ltr
      -rw-r--r-- 1 app app 524735205 Jun  3 16:00 pas.1.log.1
      -rw-r--r-- 1 app app         0 Jun  3 16:00 pas.1.log
      -rw-r--r-- 1 app app 390620136 Jun  3 16:00 pas.log.1
      -rw-r--r-- 1 app app  56195882 Jun  3 16:00 pas.log
      
      >ls -ltr
      -rw-r--r-- 1 app app 524735205 Jun  3 16:00 pas.1.log.2
      -rw-r--r-- 1 app app 390620136 Jun  3 16:00 pas.log.2
      -rw-r--r-- 1 app app 524610653 Jun  3 17:00 pas.1.log.1
      -rw-r--r-- 1 app app         0 Jun  3 17:00 pas.1.log
      -rw-r--r-- 1 app app 360170298 Jun  3 17:00 pas.log.1
      -rw-r--r-- 1 app app     11416 Jun  3 17:00 pas.log
      

      Attachments

        Activity

          People

            logback-dev Logback dev list
            asabbi Anup Sabbi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: