Take the 2-minute tour ×

I've in my logback.xml configuration file this appender:

<appender name="FILE"
    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
      <Pattern>%d{dd MMM yyyy;HH:mm:ss} %-5level %logger{36} - %msg%n
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">


so that I specify path to file in which to print logs in a relative way through classpath, but it doesn't work, no file addressbookLog.log is created and written. It only works with absolute paths like /home/andrea/.../resources/addressbookLog.log Have you any ideas on how to make it work with classpath?

share|improve this question
add comment

2 Answers

The Chapter 3: Logback configuration: Variable substitution told us the various ways to refer to the variable defined outside, e.g. system properties and classpath.

The significant configuration is creating a separate file that will contain all the variables. We can make a reference to a resource on the class path instead of a file as well. e.g.

The logback.xml


  <property resource="resource1.properties" />

     <!-- Here we can refer to the variable 
      defined at the resource1.properties -->

   <root level="debug">
     <appender-ref ref="FILE" />

The external properties file (resource1.properties)


Please note that the resource1.properties is a resource which available at the classpath.

You may refer to the full version at Chapter 3: Logback configuration: Variable substitution. I hope this may help.

share|improve this answer
That's not really what he is asking. He wants to know how to use the classpath to specify where the destination log file is. For example, the log file in his example would be "WEB-INF/classes/addressbookLog.log" under Tomcat. But it could be in a different location in a different environment. I'm looking for the answer to the same question... –  jsumners Jul 3 '13 at 17:45
add comment

You defined the resource1.properties is absolute path.

share|improve this answer
add comment

Your Answer


