I wish to be able to specify where my log4j2 logs are going to go with either VM arguments or command line arguments.
This is different than all the questions asking how to specify the log4j properties file path.
I figured I could add -Darbitrary.path="path/to/root/dir" in the VM arguments and then reference it in log4j2.properties:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<File name="file" fileName="${arbitrary.path}/application.log">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</File>
</Appenders>
<Loggers>
<Root level="info" additivity="false">
<AppenderRef ref="file" />
</Root>
</Loggers>
</Configuration>
Alas, it appears that this does not work. Is there something I'm doing wrong, or some alternative way of getting this functionality?
[EDIT]
Based on the suggestion from @RC., I also tried adding to the command line arguments, --log-dir "/tmp/logMonitor/logs", and changed the reference to ${main:--log-dir}. This variable gets resolved, however, as "-log-dir" and puts the log file in <project_root>/-log-dir/application.log
[/EDIT]
${log4j:configParentLocation}worked for my needs, thank you!