Recently, I needed to solve one very simple problem. In JBoss, we are logging quite a lot of information. However, in our test systems, we don’t need to keep all that data. The reason to keep it is regulation wise and also in production you need to keep track of what and who is doing something.
However, this is not a good approach in a test environment. It consumes unnecessary disk space, which, if your system is used for other testing, workflows could end up in consuming entire disk space and putting your virtual machines in a halt state.
It is important to configure your testing and production system according to their expectations and needs. Sometimes replicating ALL production configuration has no sense.
There are few ways how you can have the purging of the log files in JBoss out of the box with no sweat.
You could use one of those two loggers:
- size-rotating-file-handler
- periodic-size-rotating-file-handler
What is the size-rotating-file-handler
This handler provides you with the opportunity to split the big log file into smaller. Sometimes you can end up with log files larger than 1GB and this is a lot. You will need a special tools to open such files and it is really not comfortable for anyone who needs to investigate issues.
Therefore, having a size limit is so crucial.
<size-rotating-file-handler name="FILE" autoflush="true" rotate-on-boot="true">
<rotate-size value="400m"/>
<max-backup-index value="10"/>
<append value="false"/>
</size-rotating-file-handler>
if you had set the rotate-size value, then when the log file size reaches the configured size, JBoss will create a new log file.
And if you set the backup-index, then when 10 times 400m is reached, which is approximately 4GB, JBoss will overwrite the old logs and this is how your disk space will be kept under control.
What is periodic-size-rotating-file-handler
To achieve a daily logging and purging, after certain days you could use the periodic-size-rotating-file-handler.
To do that, you will need to predict what would be the most of the log file size per day.
NOTE: if one day there aren’t any events logged, JBoss won’t create a file for it.
After that, by configuring the max-backup-index you can set for how many days you would like to keep the log files.
<periodic-size-rotating-file-handler name="FILE" ...><rotate-size value="400m"/> <max-backup-index value="7"/> <suffix value=".yyyy-MM-dd"/> ... </periodic-size-rotating-file-handler>
I hope this information is useful for all of you configuring JBoss servers!
Aleks Vladimirov
Solution Engineering Manager at Thales | Senior IT Professional | Startup Mentor and Product Manager