Pass variable/parameter to logback.xml

By xngo on February 21, 2019

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:

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>${USER_HOME}/myApp.log</file> <!-- USER_HOME = /home/sebastien -->
  <root level="debug">
    <appender-ref ref="FILE" />



About the author

Xuan Ngo is the founder of He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.