I have a log4j.xml config file. and a RollingFileAppender to which I need to provide file path for storing logs. The problem is my code will be deployed on Unix machine as a runnable jar. So if I pass parameter something like this:
value=logs/messages.log"
it creates folder named logs inside my HOME directory and writes all the messages to file inside this directory.
I have a environmental variable set to some value. I want to use path of that variable and write messages under that path. How can I achieve it?
I had tried using this:
value="${MY_HOME}/logs/message.log"
but this does not work. Can anyone suggest a solution for this problem?
When parsing its configuration file, the expression
${MY_HOME}will be expanded to the value of the system property namedMY_HOME, not the system environment variable. There’s a difference between the two.To achieve this in a clean way, you’ll have to add something like this to the JVM invocation line:
-DMY_HOME=$MY_HOMEThat would define the Java system property
MY_HOMEto contain the value of the environment variableMY_HOME.