简体   繁体   English

如何为Java的GC日志指定时区?

[英]How to specify time zone for Java's GC log?

I've configured my JVM to write Garbage Collection stats to a log file, with options like: 我已经将我的JVM配置为将垃圾收集统计信息写入日志文件,其中包含以下选项:

-XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=64M

The problem is, my application's server log uses UTC for log messages, but the GC log uses the server time zone, which is currently 4 hours behind UTC. 问题是,我的应用程序的服务器日志使用UTC作为日志消息,但GC日志使用的服务器时区目前比UTC晚4个小时。 This makes it a little harder to reconcile events in my server log with GC pauses. 这使得在我的服务器日志中与GC暂停协调事件变得有点困难。

Is there any way to configure which time zone the Java GC log uses? 有没有办法配置Java GC日志使用的时区?

I'm on Java 7. 我在使用Java 7。

If you are on Linux you can set TZ variable to UTC . 如果您使用的是Linux,则可以将TZ变量设置为UTC Eg 例如

TZ=UTC java -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Xloggc:gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=1 -XX:GCLogFileSize=64M SomeClass

Or globally (or in a script, that starts your application): 或全局(或在脚本中,启动您的应用程序):

export TZ=UTC

This will modify the timestamps of java GC log. 这将修改java GC日志的时间戳。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM