I want to use logback logging with maven-jetty-plugin. Apparently, the system property logback.configurationFile is read after maven-jetty-plugin is started and has initialized slf4j, so the file ./src/test/resources/logback.xml isn't read by jetty. As a result, I get all log messages set to debug level and printed to console (a default logback configuration). Launching maven with -Dlogback.configurationFile=... resolves the problem. However, I'd prefer setting the property in the pom as it is possible with log4j and maven-jetty-plugin. Any ideas ?
Here is my pom.xml:
...
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.0.4.v20111024</version>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<configuration>
<systemProperties>
<systemProperty>
<name>logback.configurationFile</name>
<value>./src/test/resources/logback.xml</value>
</systemProperty>
</systemProperties>
...
And here is logback.xml:
<configuration>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logFile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
It works with Jetty 9 and the jetty-maven-plugin:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webAppSourceDirectory>src/main/resources/htdocs</webAppSourceDirectory>
<webApp>
<descriptor>src/main/webapp/WEB-INF/web.xml</descriptor>
</webApp>
<systemProperties>
<systemProperty>
<name>org.eclipse.jetty.util.log.Log</name>
<value>org.eclipse.jetty.util.log.Slf4jLog</value>
</systemProperty>
<systemProperty>
<name>logback.configurationFile</name>
<value>src/main/resources/logback.xml</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>