GC log rotation data lose on application restart

alid picture alid · Oct 9, 2013 · Viewed 7.4k times · Source

I use this jvm option in order to create gc logs and enable rolling:

$ java -Xloggc:gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5  XX:GCLogFileSize=128K

However, I have a problem when I restart my application. After a restart, the first log file gc.log.0 is overwritten and the data of that file is not rolled to gc.log.1 and hence lost.

I'm wondering if I'm right and if there's a solution for this.

Thanks in advance!

Answer

Krzysztof Krasoń picture Krzysztof Krasoń · Apr 3, 2016

You can also use java own timestamps for that:

java -Xloggc:gc-%t.log ...(rest of your line)...

%t will be replaced with a timestamp by java (see https://bugs.openjdk.java.net/browse/JDK-6950794 for information and other formats supported by -Xloggc