How do I delete old JBoss logs?

Dave picture Dave · Apr 14, 2014 · Viewed 9.8k times · Source

I'm using JBoss 7.1.3 on Mac 10.9.1. This is a development machine. How do I delete old server logs that appear under the

$JBOSS_HOME/standalone/log

directory? Ideally, I'd like logs older than 4 days to be deleted from my system, freeing up disk space.

Answer

amitsalyan picture amitsalyan · Apr 15, 2014

I am not sure whether you can auto delete files based on time lines of 4 days, the

<periodic-rotating-file-handler> 

does not have the provision to do so. However since your requirement is to free the disk space you can achieve that by using your config file (standalone or domain.xml).

By default the config file logging setting comes with periodic-rotating-file setting which looks like:

       <periodic-rotating-file-handler name="FILE" autoflush="true">
            <formatter>
                <pattern-formatter pattern="%d{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>

Please change it to size-rotating-file-handler and define the log size(rotate-size) that you would want to maintain and the number of files(max-backup-index) by doing this you have fixed the size of your log directory and always rotate within the given size allocations.

       <size-rotating-file-handler name="FILE" autoflush="true" >
            <formatter>
                <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
            </formatter>
            <file relative-to="jboss.server.log.dir" path="server.log"/>
            <append value="true"/> 
            <rotate-size value="10000K"/>
        <max-backup-index value="3"/>
        </size-rotating-file-handler>

Note that suffix does not work with <size-rotating-file-handler> For more info