How to give environmental variable path for file appender in configuration file in log4j
Solution 1:
When parsing its configuration file, the expression ${MY_HOME}
will be expanded to the value of the system property named MY_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_HOME
That would define the Java system property MY_HOME
to contain the value of the environment variable MY_HOME
.
Solution 2:
you CAN give it environment variables. Just preppend env: before the variable name, like this:
value="${env:MY_HOME}/logs/message.log"