Enabling garbage collection logging with Tomcat on a Linux/UNIX platform
search cancel

Enabling garbage collection logging with Tomcat on a Linux/UNIX platform

book

Article ID: 293342

calendar_today

Updated On:

Products

VMware Tanzu tc Server

Issue/Introduction

This article provides information about how to enable garbage collection logging with Apache Tomcat or Pivotal tc Server Runtime on a Linux or UNIX platform.

In all of these cases, you need to add options to the Java executable, but the method is different for each product. The same method can be used for specifying other options for Java.

For each product, the example in this article assumes that the GC log should go (as specified using -Xloggc) to the same standard location as other logs.

Several recommended parameters are given in the examples.

You may need to adjust the examples according to your requirement.

Environment


Resolution

Apache Tomcat

To enable garbage collection logging with Apache Tomcat, follow the instructions below:

1. Create a file named setenv.sh in the $TOMCAT_HOME/bin directory.
 
2. Add these entries to the file:
 
export CATALINA_OPTS="-XX:+PrintGCTimeStamps \
-XX:+PrintGCDetails \
-XX:+PrintGCApplicationStoppedTime \
-XX:+PrintGCApplicationConcurrentTime \
-XX:+PrintHeapAtGC \
-Xloggc:logs/gc.log"
Note: If the setenv.sh already exists, you need to merge these entries with the existing options.
 
This script is executed when Apache Tomcat is started and sets the JVM options needed to enable garbage collection logging.
 
3. Restart Apache Tomcat to enable the changes.


Pivotal tc Server Runtime


To enable garbage collection logging under tc Server:
1. Open the bin/setenv.sh script for an instance of the runtime using a text editor.
 
2. Locate the JVM_OPTS variable.
 
3. To enable garbage collection logging, modify and add the following:
 
JVM_OPTS="-XX:+PrintGCTimeStamps \
-XX:+PrintGCDetails \
-XX:+PrintGCApplicationStoppedTime \
-XX:+PrintGCApplicationConcurrentTime \
-XX:+PrintHeapAtGC \
-Xloggc:logs/gc.log"

4. Restart the runtime instance for the changes to take effect.