title: How does Wildfly know that a number of files need to be deleted if the "max-backup-index" attribute has been configured?
body: <p>In order to implement <a href="https://issues.jboss.org/browse/LOGMGR-57" rel="nofollow">this issue</a>, i.e., <code>max-backup-index</code> feature for <code>periodic-rotating-file-handler</code> I am trying to understand how the <code>max-backup-index</code> attribute works in the <code>size-rotating-file-handler</code>.</p>
  
  <p><strong>Attempts</strong></p>
  
  <p>Wildfly reads the xml configuration:</p>
  
  <pre><code>&lt;size-rotating-file-handler name="FILE" autoflush="true"&gt;
      &lt;level name="INFO"/&gt;
      &lt;formatter&gt;
          &lt;pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/&gt;
      &lt;/formatter&gt;
      &lt;file relative-to="jboss.server.log.dir" path="server.log"/&gt;
      &lt;rotate-size value="100K"/&gt;
      &lt;max-backup-index value="10"/&gt;
      &lt;append value="true"/&gt;
  &lt;/size-rotating-file-handler&gt;
  </code></pre>
  
  <p>If the number of log files is greater than 10, then Wildfly will remove the files until 10 are left.</p>
  
  <p>The Wildfly code that resides on Github has been viewed in order to understand what code is responsible for reading the <code>&lt;max-backup-index value="10"/&gt;</code> snippet and removing the superfluous log files.</p>
  
  <p><a href="https://github.com/wildfly/wildfly-core/blob/2b3f2bdd9533b28a30e32150f6c903cd50de3101/logging/src/main/java/org/jboss/as/logging/PeriodicSizeRotatingHandlerResourceDefinition.java" rel="nofollow">PeriodicSizeRotatingHandlerResourceDefinition</a></p>
  
  <pre><code>class PeriodicSizeRotatingHandlerResourceDefinition extends AbstractFileHandlerDefinition {
  
      public static final String PERIODIC_SIZE_ROTATING_FILE_HANDLER = "periodic-size-rotating-file-handler";
      static final PathElement PERIODIC_SIZE_ROTATING_HANDLER_PATH = PathElement.pathElement(PERIODIC_SIZE_ROTATING_FILE_HANDLER);    
  
      static final AttributeDefinition[] ATTRIBUTES = Logging.join(DEFAULT_ATTRIBUTES, AUTOFLUSH, APPEND, MAX_BACKUP_INDEX, ROTATE_SIZE, ROTATE_ON_BOOT, SUFFIX, NAMED_FORMATTER, FILE);
  
      public PeriodicSizeRotatingHandlerResourceDefinition(final ResolvePathHandler resolvePathHandler) {
          super(PERIODIC_SIZE_ROTATING_HANDLER_PATH, false, PeriodicSizeRotatingFileHandler.class, resolvePathHandler, ATTRIBUTES);
      }
  </code></pre>
  
  <p>super refers to the constructor of the superclass, i.e, <a href="https://github.com/wildfly/wildfly-core/blob/2b3f2bdd9533b28a30e32150f6c903cd50de3101/logging/src/main/java/org/jboss/as/logging/AbstractFileHandlerDefinition.java" rel="nofollow">AbstractFileHandlerDefinition</a></p>
  
  <pre><code>abstract class AbstractFileHandlerDefinition extends AbstractHandlerDefinition {
      protected AbstractFileHandlerDefinition(final PathElement path, final boolean registerLegacyOps,
                                              final Class&lt;? extends Handler&gt; type,
                                              final ResolvePathHandler resolvePathHandler,
                                              final AttributeDefinition... attributes) {
          super(path, registerLegacyOps, type, new DefaultPropertySorter(FileNameLastComparator.INSTANCE), attributes);
          this.registerLegacyOps = registerLegacyOps;
          this.resolvePathHandler = resolvePathHandler;
      }
  </code></pre>
  
  <p>super refers to <a href="https://github.com/wildfly/wildfly-core/blob/2b3f2bdd9533b28a30e32150f6c903cd50de3101/logging/src/main/java/org/jboss/as/logging/AbstractHandlerDefinition.java" rel="nofollow">AbstractHandlerDefinition</a> </p>
  
  <pre><code>abstract class AbstractHandlerDefinition extends TransformerResourceDefinition {
  
      protected AbstractHandlerDefinition(final PathElement path,
                                          final boolean registerLegacyOps,
                                          final Class&lt;? extends Handler&gt; type,
                                          final PropertySorter propertySorter,
                                          final AttributeDefinition[] attributes) {
          this(path, registerLegacyOps, type, propertySorter, attributes, null, attributes);
      }
  </code></pre>
  
  <p><strong>Current outcome</strong></p>
  
  <p>At the moment it feels like I am lost in a labyrinth. I cannot find the code that explains the interaction between the <code>max-backup-index</code> attribute and the <code>size-rotating-file-handler</code>.</p>