Logging with log4j in jetty-maven-plugin

The jetty-maven-plugin is a great way to run a webapp during development. But the main problem is that it doesn’t print debug messages when you are using commons-logging. The reason is that it by default uses org.apache.commons.logging.impl.SimpleLog. This logger can’t print debug messages. Here is the solution on how to change this default behaviour so that it use Log4J instead.

Add this to your pom.xml inside the <plugins> tag:

    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">

Note that I point to a ./jetty/log4j.properties file. This could look something like:

log4j.rootCategory=ERROR, A1
log4j.appender.A1.layout.ConversionPattern=%d %-4r [%t] %-5p %c %x - %m%n

This will print all log messages to your console.

2 thoughts on “Logging with log4j in jetty-maven-plugin

  1. Does it work after jetty detects a change and restarts? I’ve got problems with log4j complaining about missing appenders, resulting in zero logging after jetty restarts. 🙁

  2. Hmmm, I’m really not sure about that. I haven’t noticed this problem. I will do some testing, and come back to you if I am able to reconstruct this behaviour.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.