In this article I’ll provide information about how to enable garbage collection logging (GC logs) in Apache tomcat.
GC logs are very important when you are debugging an application. GC logs helps to analyse how your program uses the memory.
GC logs also helps to find how often garbage collector cleans the memory for unused objects.
So, you can enable garbage collection logging in few simple steps, that are as follows:
for this you need a file named setenv.sh in the $TOMCAT_HOME/bin directory. Create one if it doesn’t exists.
setenv.sh is executed when Apache Tomcat is started and sets the JVM options needed to enable garbage collection logging.
how to enable garbage collection logging
Add these lines to setenv.sh
export CATALINA_OPTS=” \
Restart Apache Tomcat to enable the changes.
look into tomcat’s logs directory you will find gc.log file, and you can analyse your GC logs 🙂