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

SizeAndTimeBasedRollingPolicy on Windows sometimes exceeds maxFileSize and file counter explodes

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • 1.2.3
    • logback-core
    • None
    • Windows Server 2012 R2

    Description

      I have at least two cases where the maxFileSize (5MB) was exceeded and the file counter exploded.

      xxx.2017-10-11.5.json with 5MB
      xxx.2017-10-11.12186.json 32.4MB
      xxx.2017-10-11.12187.json 1.33MB

      xxx.2017-10-19.8.json with 5MB
      xxx.2017-10-19.1626.json with 8.98MB
      xxx.2017-10-19.1627.json with 2.82MB

      My guess is, that the log file had a size of 4.99MB and then several threads simultaneously wrote into the same log file and therefore parallel rollovers occurred?

      <appender name="JSON_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${fileNamePrefix}.json</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
          <!-- daily rollover -->
          <fileNamePattern>${fileNamePrefix}.%d{yyyy-MM-dd}.%i.json</fileNamePattern>
          <!-- keep 30 days' worth of history -->
          <maxHistory>30</maxHistory>
          <!-- each file should be at most 5MB -->
          <maxFileSize>5MB</maxFileSize>
        </rollingPolicy>
        <!-- encoders are assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
          <providers>
            <timestamp>
              <fieldName>timestamp</fieldName>
            </timestamp>
            <logLevel>
              <fieldName>logLevel</fieldName>
            </logLevel>
            <threadName>
              <fieldName>threadName</fieldName>
            </threadName>
            <loggerName>
              <fieldName>loggerName</fieldName>
            </loggerName>
            <callerData>
              <classFieldName>className</classFieldName>
              <methodFieldName >methodName</methodFieldName>
              <fileFieldName>[ignore]</fileFieldName>
              <lineFieldName>lineNumber</lineFieldName>
            </callerData>
            <message />
            <stackTrace>
              <fieldName>stackTrace</fieldName>
              <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
                <maxDepthPerThrowable>30</maxDepthPerThrowable>
                <rootCauseFirst>true</rootCauseFirst>
              </throwableConverter>
            </stackTrace>
          </providers>
        </encoder>
      </appender>
      

      Attachments

        Activity

          People

            logback-dev Logback dev list
            mwe@ebp.de Martin Wegner
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: