The way to pass variables or parameters to the logback.xml
configuration file is to use Java system properties.
Java system properties can be set on the command line as follows:
java -DUSER_HOME="/home/sebastien" MyApp2
- USER_HOME is the variable name that you want to pass to the
logback.xml
configuration file.
Here is how you use it within the logback.xml
configuration file:
<configuration> <appender name="FILE" class="ch.qos.logback.core.FileAppender"> <file>${USER_HOME}/myApp.log</file> <!-- USER_HOME = /home/sebastien --> <encoder> <pattern>%msg%n</pattern> </encoder> </appender> <root level="debug"> <appender-ref ref="FILE" /> </root> </configuration>
Reference
- http://logback.qos.ch/manual/configuration.html#variableSubstitution2