Rolling garbage collector logs in java

前端 未结 6 931
孤街浪徒
孤街浪徒 2020-12-08 04:12

Is it possible to do a rolling of garbage collector logs in Sun JVM?

Currently I generate logs using:

-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:         


        
6条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 04:40

    If you can't upgrade your java version to use the new flags for rotating the gc log then you could specify a different gc file each time the application starts:

    JAVA_OPTS="-Xms1024m -Xmx1024m -XX:MaxPermSize=256m -verbose:gc -XX:+PrintGCTimeStamps -XX:+PrintGCDetails -Xloggc:/path/to/log/dir/gc.log-"`date +%Y-%m-%d-%H-%M`
    

    When the setenv is referenced, usually at startup or shutdown, it will reference a different log file. In unix this can be used as a method for 'rotating' the log.

提交回复
热议问题