javajvmjvm-argumentscrash-log

How to specify a unique name for the JVM crash log files?


When the JVM crashes it generates a log file that is saved (by default) in the current folder of the application and has a name respecting the following format: hs_err_pid[PID].log

I need to make the JVM save this file in a different folder with a desired name. So, I use this command line argument for the virtual machine:

-XX:ErrorFile=./log/jvm_error_pid%p.log

It is working, but I don't like something about this solution. Let's assume the log folder already contains a file named jvm_error_pid5000.log. If there is a future crash on a JVM that has 5000 PID, then JVM does not override the jvm_error_pid5000.log file from the log folder and it saves this log file in a totally different place (from what I tested in the TEMP folder of the current OS user). It doesn't even rename the new file by appending a random string to assure uniqueness.

I haven't found anything regarding this uniqueness problem on the Oracle documentation page about crash log files. I would like to know if there is a way to improve that command line argument so that it will always generate different crash log file names. For example, I want to use the command line argument to put the date and hour in the file name:

-XX:ErrorFile=./log/jvm_error_pid%p_%d_%h.log

Solution

  • JVM does not expand placeholders in ErrorFile other than %p. But you may modify your shell script that launches Java, and use shell variables instead.

    #!/bin/bash
    TS=`date +%F-%H%M%S`
    java -XX:ErrorFile=/tmp/hserr_%p_$TS.log ...