title: Log4j2 - Compressing aged Rollover Files, keep last X file uncompressed
body: <p>How to compress <strong>only older rolled files</strong> and not every time it rolls? (now it is every day). The following configuration only rolls daily and delete compressed file after 60 days, but it compresses every day.</p>
  
  <p>I don't want to use a tool to decompress the file of the last [X] days if I have to investigate in them...</p>
  
  <pre><code>&lt;RollingRandomAccessFile name="file" fileName="${baseDir}/app-trace.log"
                 filePattern="${baseDir}/app-trace-%d{yyyy-MM-dd}.log.gz"
                 immediateFlush="false" append="true"&gt;
      &lt;PatternLayout pattern="%d %-5p [%t] %c - %m%n"/&gt;
      &lt;Policies&gt;
          &lt;TimeBasedTriggeringPolicy/&gt;
      &lt;/Policies&gt;
      &lt;DefaultRolloverStrategy max="91"&gt;
          &lt;Delete basePath="${baseDir}" maxDepth="2"&gt;
              &lt;IfFileName glob="*/app-trace*.log.gz"&gt;
                  &lt;IfLastModified age="60d"&gt;
                      &lt;IfAny&gt;
                          &lt;IfAccumulatedFileSize exceeds="1 GB"/&gt;
                          &lt;IfAccumulatedFileCount exceeds="10"/&gt;
                      &lt;/IfAny&gt;
                  &lt;/IfLastModified&gt;
              &lt;/IfFileName&gt;
          &lt;/Delete&gt;
      &lt;/DefaultRolloverStrategy&gt;
  &lt;/RollingRandomAccessFile&gt;
  </code></pre>