如何将致命错误的时间戳添加到Java致命错误日志文件名中
背景
- 您可以使用
Java -XX:errorfile =/path/to/file
来指定致命错误日志文件的路径。 - 您可以使用
-XX:ONERROR
选项在Java VM上导致错误时执行命令。 - 为了保持致命的错误日志,我想将致命错误发生的时间戳添加到文件名中。
问题
我试图设置这样的Java VM选项:
java -XX:ErrorFile=/path/to/error.log -XX:OnError="mv /path/to/error.log /path/to/error_store/error_$(date +%F-%H%M%S).log" -jar /path/to/application.jar
但是,当Java VM上发生错误时,文件名上的时间戳是Java VM启动的时间,而不是致命错误发生的时间。
问题
是否有任何方法可以将致命错误发生的时间戳添加到Java致命误差日志文件名中?
Background
- You can use
java -XX:ErrorFile=/path/to/file
to specify the path of fatal error log file. - You can use the
-XX:OnError
option to execute a command when an error causes on a Java VM. - To maintain the fatal error logs, I want to add the timestamp of the fatal error occurrence to the filename.
Problem
I have tried to set the Java VM option like this:
java -XX:ErrorFile=/path/to/error.log -XX:OnError="mv /path/to/error.log /path/to/error_store/error_$(date +%F-%H%M%S).log" -jar /path/to/application.jar
But when an error occurs on Java VM, the timestamp on the filename is the time of the Java VM's startup, rather than the time of occurrence of the fatal error.
Question
Is there any way to add the timestamp of the fatal error occurrence to the Java fatal error log filename?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个解决方案。为了使命令扩展以后有效,您必须将
$
作为字面形式传递(使用\ $(...)
)类似:当发生致命错误时,执行以下命令:
I found a solution. To make the command expansion works later, you have to pass
$
as a literal (use\$(...)
) like:and when a fatal error occurred, the following command was executed: