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!
Developers take advantage of the JVM argument -XX:+UseGCLogFileRotation to rotate GC log files. As shown above, the JVM will rotate the GC log file whenever its size reaches 20MB.
But the challenge to this approach is: whenever the application is restarted, old GC log file will be over-ridden by the new GC log file as the file path is same (i.e. /home/GCEASY/gc.log). Thus you wouldn’t be able to analyze the old GC logs that existed before restarting the application.
Now new GC logs will be written to gc.log.0 file and old GC log content will be present in gc.log.1, gc.log.2, gc.log.3, gc.log.4 i.e. So your new GC log contents get mixed up with old GC logs.
It uses the Native logrotate command instead of manually copying and performing the log rotation It leaves no log file (or) footprint in the file system as the output is directly printed to STDOUT, If you would like to save the output to a file you can use runtime redirection using > logfilename 2>&1
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With