Logging with maven-jetty-plugin

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 slf4j is initialized, therefore the file. /src/test/resources/logback.xml the berth cannot be read. As a result, I get all log messages configured to the debug level and printed to the console (the default configuration for the log). Running maven with -Dlogback.configurationFile = ... fixes the problem. However, I would prefer to set the property to pom, as 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> 
+8
maven jetty maven-jetty-plugin logback
source share
4 answers

Using an older maven-jetty-plugin rather than jetty-maven-plugin works for me:

 <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.26</version> <configuration> <systemProperties> <systemProperty> <name>logback.configurationFile</name> <value>${project.build.outputDirectory}/jetty-logback.xml</value> </systemProperty> </systemProperties> </configuration> <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.6.4</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.0.0</version> </dependency> </dependencies> </plugin> 
+3
source share

It works with Jetty 9 and the jetty 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> 
+6
source share

you can use Properties-Maven-Plugin:

 <project> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>properties-maven-plugin</artifactId> <version>1.0-alpha-2</version> <executions> <execution> <goals> <goal>set-system-properties</goal> </goals> <configuration> <properties> <property> <name>logback.configurationFile</name> <value>src/test/resources/logback.xml</value> </property> </properties> </configuration> </execution> </executions> </plugin> </plugins> </build> </project> 

Documentation: http://mojo.codehaus.org/properties-maven-plugin/usage.html
This is not ideal, but it should work.

+3
source share

I ran into the same problem. As a workaround, I used slf4j-simple instead of logback. Slf4j-simple has a default configuration set to INFO, but otherwise it cannot be configured, so it may or may not suit your needs. In the plugin configuration, replace logback-classic with:

  <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-simple</artifactId> <version>1.6.4</version> </dependency> 
+2
source share

All Articles