Search code examples
wildflywildfly-10

How to configure compressed logs in WildFly?


Is it possible to configure compressed logs in WildFly 10? Was not able to find the proper configuration here: https://docs.jboss.org/author/display/WFLY10/Handlers


Solution

  • Log handlers are not supposed to zip log files. I assume, that you want to use log rotation and then zip older log entries. First, define a rotated file handler - you can decide to rotate either based on time e.g. every midnight or based on size e.g. every 5MB. An example of time based, daily rolling file handler:

    <periodic-rotating-file-handler name="FILE" autoflush="true">
       <formatter>
           <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
       </formatter>
       <file relative-to="jboss.server.log.dir" path="server.log"/>
       <suffix value=".yyyy-MM-dd"/>
       <append value="true"/>
    </periodic-rotating-file-handler>
    

    Now for the second part, compression. If you are on linux, the easiest way ho to do that is to setup a CRON job that would find all entries that you want to zip and compress them. For example you can setup your cron job to run this script:

    ls server.log.*|grep -v '\.zip$' |xargs -i zip -m {}.zip {}