Profile Image
Jesse Hardy

Is there any flags/options to add to java configuration for log rotation?

I'm want to know what the best flags/options are to add to my java configuration for log rotation.

 

Thanks,

Jesse



Report URL - https://gceasy.io/my-gc-report.jsp?p=c2hhcmVkLzIwMjEvMDUvNC8tLWdjLmxvZy0tMTItMTYtMjQ=&channel=WEB

  • logrotation

  • javaconfiguration

Please Sign In or to post your comment or answer

Profile Image

Mahesh

Hello Jesse!

 

As per my knowledge, the following flags are important for log rotation:

 

-Xloggc:gc.log -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:GCLogFileSize=10m -XX:NumberOfGCLogFiles=10

 

  1. XX:+PrintGCDateStamps - This flag is not needed but if you use it, it will help you to analyze the events in the log file because it prefixes lines with human readable timestamp.
  2.  -XX:-UseGCLogFileRotation - This flag is used to enable log rotation.
  3. -XX:GCLogFileSize - This flag is used to define your log file size. The default value is 512k. In the above example, I used 10MB. After 10MB log will be rotated. You should avoid very high values that will cause memory issues.
  4. -XX:NumberOfGCLogFiles - This flag is used to define the number of files you want to use in log rotating. You are free to keep more files unless you wish to keep data for later analysis.

Profile Image

Ram Lakshmanan

Hello Jesse!

 

 Greetings. 

 

 '-XX:-UseGCLogFileRotation' argument proposed by Mahesh is supported out-of-the-box by the JVM. But this argument has several undesirable effects. To name a few:

 

a. You will lose old historical GC log files

b. GC events can get mixed up

c. Forwarding GC logs to a central location (like splunk) will become a challenge.

d. GC log parsing can also become challenging

 

 More details on these undesirable side-effects are discussed in this blog post.

 

 I will recommend not passing  '-XX:-UseGCLogFileRotation' but only pass "-Xloggc:/home/GCEASY/gc-%t.log" to your application. '%t' in the argument will suffix timestamp at which the JVM was restarted. 

 

‘%t’ suffixes timestamp to the gc log file in the format: ‘YYYY-MM-DD_HH-MM-SS’. So generated GC log file name will start to look like: ‘gc-2019-01-29_20-41-47.log’

 

This will make GC Log file locations will become unique. Then new GC logs will not over-ride the old GC logs. All old GC logs can be archived. 

 

 

 

Got something else on mind? Post Your Question

Not the answer you're looking for? Browse other questions tagged
  • logrotation

  • javaconfiguration