# Enabling GC logging for a DataSource's JVM

Caplin Support recommend enabling garbage collection (GC) logging for production Java virtual machines (JVMs). Garbage collection logs provide valuable information for tuning a JVM’s heap size and investigating performance and memory problems.

For a detailed reference on JVM logging options, see the [`**java**` command reference](https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html) (Java 8) and [Unified JVM Logging](https://openjdk.org/jeps/158) (Java 11).

## Enabling GC logging for a C DataSource

C DataSources include [Liberator](../liberator/index.md), [Transformer](../transformer/index.md), and the [TREP Adapter](../../../trep-adapter/index.md).

The following examples show the [`jvm-options`](datasource-java-jvm-configuration.md#jvm-options) used to configure GC logging for versions of Java supported by Caplin Platform 7. Add the appropriate configuration below to your DataSource’s `java.conf` file:

**Java 8**

```
jvm-options -XX:+PrintGCDetails
jvm-options -XX:+PrintGCDateStamps
jvm-options -XX:+UseGCLogFileRotation
jvm-options -XX:NumberOfGCLogFiles=10
jvm-options -XX:GCLogFileSize=5M
jvm-options -XX:+PrintConcurrentLocks
jvm-options -XX:+PrintCommandLineFlags
jvm-options -XX:+HeapDumpOnOutOfMemoryError ①
jvm-options -XX:HeapDumpPath=var
```

**Java 11**

```
jvm-options -Xlog:gc:file=var/gc-%p.log:tags,time,uptime,level:filecount=10,filesize=5M
jvm-options -XX:+HeapDumpOnOutOfMemoryError ①
jvm-options -XX:HeapDumpPath=var
```
1. If the DataSource’s JVM runs out of memory, dump the JVM heap before terminating the JVM. A heap dump can provide valuable information to Caplin Support.

## Enabling GC logging for a Java DataSource

Java DataSources include [Caplin RET Adapter Toolkit](../../../ret-adapter-suite/index.md), the [Caplin Barracuda Adapter](../../../barracuda-order-adapter/index.md), and the [Caplin Wallstreet Adapter](../../../wallstreet-adapter/index.md).

To enable GC logging for a Java DataSource, add the appropriate command-line options below to the `**java**` command in the DataSource’s `DataSource/bin/start-jar.sh` script:

**Java 8**

```
-Xloggc:var/gc-%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=5M -XX:+PrintConcurrentLocks -XX:+PrintCommandLineFlags -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=var
```

**Java 11**

```
-Xlog:gc:file=var/gc-%p.log:tags,time,uptime,level:filecount=10,filesize=5M -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=var
```

---

**See also:**

* [`**java**` command reference](https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html) (Java 8)
* [Unified JVM Logging](https://openjdk.org/jeps/158) (Java 11)
