The log of the JVM's GC is written in a replacement (>) instead of append (>>), and the previous GC content is emptied if it is written to the same file the next time. This causes the history of GC logs to be lost after we restart the Java service.
-xx:+printgc
-xx:+printgcdetails
-xx:+printgctimestamps
-xloggc:filename
Example
This will cause the GC log to be lost after the Java service restarts
-xx:+printgcdetails-xx:+printgctimestamps-xloggc:/data0/logs/gc.log
Here the GC logs support%p and%t two parameters:
%p will be replaced with the corresponding process PID
%t will be replaced by a time string in the form of: YYYY-MM-DD_HH-MM-SS
This way, the GC history log will not be lost, no matter how it restarts
-xx:+printgcdetails-xx:+printgcdatestamps-xloggc:/data0/logs/gc-%t.log "
Short-term cloud computing training: Tracking garbage collection for Java virtual machines