在java中滚动垃圾收集器日志 [英] Rolling garbage collector logs in java

查看:371
本文介绍了在java中滚动垃圾收集器日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



目前我使用以下方式生成日志:

  -XX:+ PrintGCDetails -XX:+ PrintGCTimeStamps -XX:+ PrintGCDateStamps -verbose:gc -Xloggc:gc.log 

但我必须使用fifo队列和rotatelogs来手动轮换它们以创建每天的新日志。我希望有更好的解决方案。



也许有从java内部访问这些日志条目的方法,所以我可以将它们重定向到log4j?



编辑:使用fifo队列的解决方案不够好,因为如果从这个队列读取的进程(例如rotatelogs)读取速度较慢,它会减慢整个jvm(显然是Sun / Oracle同步执行gc日志记录)

解决方案

对HotSpot JVM添加了对GC日志旋转的内置支持。
它在 RFE 6941923 中进行了描述,可在以下位置获得:





有三个新的JVM标志可用于启用和配置它:


  • -XX:+ UseGCLogFileRotation
    必须与 -Xloggc:< filename> ;
  • 一起使用
  • -XX:NumberOfGCLogFiles =<文件数量>
    必须> = 1,默认值为1;
  • - XX:GCLogFileSize =< number> M(或K)
    默认值将设为512K。


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

Currently I generate logs using:

-XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -verbose:gc -Xloggc:gc.log 

But I have to manually rotate them using fifo queues and rotatelogs to create a new log for each day. I hope that there is a better solution for this.

Maybe there is a way to access this log entries from inside java so I could redirect them to log4j?

Edit: the solution with fifo queue is not good enough because if the process that reads from this queue (e.g. rotatelogs) reads to slow it will slow down the entire jvm (apparently Sun/Oracle does gc logging synchronously)

解决方案

Built-in support for GC log rotation has been added to the HotSpot JVM. It is described in the RFE 6941923 and is available in:

There are three new JVM flags that can be used to enable and configure it:

  • -XX:+UseGCLogFileRotation
    must be used with -Xloggc:<filename>;
  • -XX:NumberOfGCLogFiles=<number of files>
    must be >=1, default is one;
  • -XX:GCLogFileSize=<number>M (or K)
    default will be set to 512K.

这篇关于在java中滚动垃圾收集器日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆