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

Prevent IndexOutOfBoundsException caused by misconfiguration

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 1.0.13
    • Fix Version/s: None
    • Component/s: logback-classic
    • Labels:
      None
    • Environment:

      <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
      <version>1.0.13</version>
      </dependency>

      Description

      I ran into exactly this http://tonaconsulting.com/error-in-ch-qos-logback-core-joran-spi-interpreter2325-runtimeexception-in-action-for-tag-rollingpolicy-java-lang-indexoutofboundsexception-no-group-1/ (apparently someone else too) and believe that it could be detected when reading the configuration. I would prefer getting an invalid configuration exception at startup compared to the current runtime exception that only occurs rarely.

      Example wrong config:
      <fileNamePattern>var/log/mylog.log.%d

      {yyyy-MM}.zip</fileNamePattern>

      Correct config needs counter variable:
      <fileNamePattern>var/log/mylog.log.%d{yyyy-MM}

      (%i).zip</fileNamePattern>

      The exception I received was
      java.lang.IndexOutOfBoundsException: No group 1

      Full config example:

      <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
      <file>var/log/myfile.log</file>
      <encoder>
      <pattern>%d

      {yyyy-MM-dd/HH:mm:ss.SSS/zzz}

      [%t] %-5p %m%n</pattern>
      </encoder>
      <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <fileNamePattern>var/log/myfile.%d

      {yyyy-MM}

      (%i).log.zip</fileNamePattern>
      <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
      <maxFileSize>100MB</maxFileSize>
      </timeBasedFileNamingAndTriggeringPolicy>
      <maxHistory>3</maxHistory>
      </rollingPolicy>
      </appender>

        Attachments

          Activity

            People

            Assignee:
            ceki Ceki Gülcü
            Reporter:
            fabiankessler Fabian Kessler
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: