How to enable Garbage Collection logs

Monitoring GC activity is critical to Application performance monitoring. JVM provides a very low overhead solution to enable the GC logging. Lets see how to enable Garbage collection logs

GC logs can be enabled by adding following flags while starting your Java application

-verbose:gc -> enables verbose gc mode
-XX:+PrintGCDetails -> prints the gc details like GC Type, heap summary etc
-XX:+PrintGCDateStamps -> Print Data and time stamp when the GC happens
-Xloggc -> specify the output file where GC logs are to be written, default is stdout

Lets look at how this would work

java -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:/tmp/gc.log HelloWorld

Instead of HelloWorld, specify your App’s main class.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.