Java: How to specify JVM argument -XX:ErrorFile and preserve automatic PID in filename
Asked Answered
U

2

9

I am using the JNI and when there is a crash due to errors in the target application a hs_err_pid*.log file is generated. I want to change the default location where that file is stored. Now, from searching around I understand this can be achieved using the JVM argument -XX:ErrorFile.

The documentation says that the default for this parameter is ./hs_err_pid<pid>.log

Now, when I override the default, how can I tell the JVM to still include the process id in the filename? I have obviously tried to literally put targetDir/hs_err_pid<pid>.log as a command line parameter, but this led to the whole argument being ignored (and the file being stored to the default location, i.e. the working directory). If I only say targetDir/hs_err_pid.log the file is stored where I want it, but does not get a process id appended to the filename.

Any suggestions would be appreciated.

Unsuccess answered 24/3, 2014 at 19:16 Comment(0)
M
17

Try

-XX:ErrorFile=targetDir/hs_err_pid_%p.log
Melchor answered 24/3, 2014 at 19:18 Comment(3)
Wow, that was fast. This looks like exactly what I was looking for. Will test tomorrow at work and post back results.Unsuccess
Perfect. Worked like a charm!Unsuccess
How can I test / simulate this? I mean, how can I cause the JVM to crash and write something in this error file?Lugsail
F
1

In Windows:

-XX:ErrorFile=C:\targetDir\hs_err_pid_%%p.log
Formulate answered 8/12, 2015 at 17:17 Comment(1)
Two percentage signs?Chiastolite

© 2022 - 2024 — McMap. All rights reserved.