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:

  1. size-rotating-file-handler
  2. 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 Vladimriov is a Senior Software Developer, recognized Project Manager and Soft-skilled trainer and a coach.

Aleks Vladimirov

Solution Engineering Manager at Thales | Senior IT Professional | Startup Mentor and Product Manager

Aleks is experienced Product Manager with an engineer background and over 10 years of experience as a software developer. He works with different governments and is responsible for negotiation features and requirements, understanding the customers’ needs and supporting the senior management with regular reports and analysis. He held various positions starting as a software developer, moving to a team leader and software architect.

He strives in waterfall and agile environment alike. He is certified Scrum Master and Prince2 Practitioner and he knows how to design business processes and help teams optimize their work.
During his tenure, he had to wear many hats, prioritizing business requirements, delegating work and mentoring team members, creating mockups with Balsamiq, providing MS Project plan to the senior management.

He had worked in many international teams, located in the same city or distributed in different countries and continents. He had been a team leader of cross functional international team of 8 people.

In his current position, he is very much client focused. He has excellent presentation skills.
He delivers training sessions on presentation skills and leadership and he had helped hundred of people to improve their presentation skills.

He is also interested in creating more positive changes in the workplace by using entrepreneurship skills.
He had won startup competition where his team had validated and develop a business idea from scratch.

In his free time, he writes in his blog about effective product development.

[cp_modal display="inline" id="cp_id_f014e"][/cp_modal]
[cp_slide_in display="inline" id="cp_id_ca87c"][/cp_slide_in]