'Log4j gc log rotation

I am using Sun JVM garbage collection logging to find out the performance of my application. Below are the parameters that I have lined up in my apache tomcat server's setenv.sh file

export CATALINA_OPTS="-server -Xms512m -Xmx1536m -XX:MaxPermSize=150m -XX:+UseConcMarkSweepGC -XX:+DisableExplicitGC -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintTenuringDistribution -XX:+PrintHeapAtGC -Xloggc:/var/tom8080/logs/gclog.txt"

The problem we are facing is that the gclog.txt is growing huge and eating up 50% of the space on the server. And still growing.

Is there a way to roll over that file and archive it in an automated fashion, similar to how you would do it for a log4j controlled file ?



Solution 1:[1]

You can add -XX:-UseGCLogFileRotation for log file rotation, -XX:NumberOfGClogFiles=n for number of files you want to save, and XX:GCLogFileSize=mfor desired log file size. There is no way to archive logs automatically, as far as I know. You can find more here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Glorfindel