Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GC log rotation data lose on application restart

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!

like image 486
alid Avatar asked Oct 09 '13 13:10

alid


People also ask

How to rotate GC log files in Java?

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.

How to analyze old GC logs before restarting the application?

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.

How to merge old GC logs with new GC logs?

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.

What is the logrotate command?

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


1 Answers

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

like image 123
Krzysztof Krasoń Avatar answered Oct 19 '22 18:10

Krzysztof Krasoń