5

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.

Kara
  • 6,115
  • 16
  • 50
  • 57
Dave
  • 15,639
  • 133
  • 442
  • 830

1 Answers1

3

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

amitsalyan
  • 658
  • 1
  • 8
  • 29
  • I switched out the "periodic-rotating-file-handler" block with your suggested "size-rotating-file-handler" block but unfortunately, after stopping and restarting my server, older files (e.g. $JBOSS_HOME/standalone/log/server.log.2013-06-18) remain. As I said, my desire is to have files older than 4 days (regardless of size) deleted. – Dave Apr 15 '14 at 18:55
  • Sorry it wont take care of historic files as it is not aware of previous configuration unless you have similiar file name format (please check the file name format). This setting will only going forward rotate the file size of each 10000k between 3 files(just an example), so at any point in time you will have only 3 log files. – amitsalyan Apr 15 '14 at 20:19