我在 MSWindows 上的 Tomcat 下运行了一个运行异常的应用程序。为了设置系统以更好地了解失败的原因,我正在尝试添加 GC 日志记录 - 但到目前为止我的尝试都失败了。
最初我在 setenv.bat 中设置了 CATALINA_OPTS - 但这些在重新启动服务时被忽略了。
然后我尝试使用 Tomcat8w.exe 添加选项:
-Xloggc:"C:\PerfLogs\gc-tomcat.log"
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=10
-XX:GCLogFileSize=5M
-XX:+PrintGCDetails
-verbose:gc
-XX:+PrintGCDateStamps
-XX:+HeapDumpOnCtrlBreak
服务启动失败,出现“错误 4”。事件查看器显示:
The Apache Tomcat 8.0 Tomcat8 service terminated with the following service-specific error: The system cannot open the file.
我检查了路径,SYSTEM 用户具有完全控制权。 Tomcat stderr 日志中没有错误报告 - 只有一个条目:
Commons Daemon procrun stdout initialized
我没有看到其他日志文件中添加了任何内容。
删除上面的选项允许服务启动。在路径上使用带有双引号的上述配置没有影响。在启动服务之前创建初始日志文件没有影响。
如何启用 GC 日志记录?我如何找出当前失败的原因?
(遗憾的是,迁移到对用户更友好的操作系统不是一种选择)。
更新 我发现了更多日志条目 - 这次是在 common-daemon-YYYY-MM-DD.log 中:
[2018-08-29 11:04:52] [info] [ 4068] Running 'Tomcat8' Service...
[2018-08-29 11:04:52] [info] [ 2560] Starting service...
[2018-08-29 11:04:52] [error] [ 4200] CreateJavaVM Failed
[2018-08-29 11:04:52] [error] [ 4200] The system could not find the environment option that was entered.
[2018-08-29 11:04:52] [error] [ 2560] Failed to start Java
[2018-08-29 11:04:52] [error] [ 2560] ServiceStart returned 4
[2018-08-29 11:04:52] [info] [ 4068] Run service finished.
[2018-08-29 11:04:52] [info] [ 4068] Commons Daemon procrun finished
并且,如果它是相关的:
java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)
最佳答案
经过大量研究,我发现 MSWindows jvm 在 Java 世界中显然是二流公民。根据Oracle Documentation MSWindows Java 引擎不支持日志循环。从配置中删除以下选项允许 JVM 使用 GC 日志记录启动:
-XX:+UseGCLogFileRotation
-XX:NumberOfGCLogFiles=10
-XX:GCLogFileSize=5M
为什么报告为“系统无法打开文件”,我不知道。
现在我只需要弄清楚当日志文件填满时会发生什么/我如何防止这种情况。
关于java - 更改 Tomcat 日志记录未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52074483/