Question

I am trying to do centralised logging of a distributed system using Log4J2 and Flume-ng. One of the servers in the system runs Jetty which I am using to do web services (servlets) for the system. When I include the Maven dependencies for Log4J2 an Flume-ng in this project it breaks Jetty and it will not start up/bind properly. If I remove the dependency in the list below (log4j-flume-ng) then Jetty will run as normal giving me the following output:

2012-10-08 16:36:33.457::INFO:  Logging to STDERR via org.mortbay.log.StdErrLog
2012-10-08 16:36:34.285 INFO net.spy.memcached.MemcachedConnection:  Added {QA sa=gs-adhoc1-test.jrs-software.co.uk/10.1.1.161:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2012-10-08 16:36:34.290 INFO net.spy.memcached.MemcachedConnection:  Connection state changed for sun.nio.ch.SelectionKeyImpl@31ac05
2012-10-08 16:36:34.272::INFO:  jetty-7.0.0.pre5
2012-10-08 16:36:34.322::INFO:  Started SelectChannelConnector@0.0.0.0:5000

But with that dependency in, it come up as (just the Memcached output):

2012-10-08 16:36:34.285 INFO net.spy.memcached.MemcachedConnection:  Added {QA sa=gs-adhoc1-test.jrs-software.co.uk/10.1.1.161:11211, #Rops=0, #Wops=0, #iq=0, topRop=null, topWop=null, toWrite=0, interested=0} to connect queue
2012-10-08 16:36:34.290 INFO net.spy.memcached.MemcachedConnection:  Connection state changed for sun.nio.ch.SelectionKeyImpl@31ac05

The dependencys in Maven POM are as follows:

<dependencies>
    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty</artifactId>
        <version>3.5.4.Final</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty</artifactId>
        <version>7.0.0.pre5</version>       
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>3.0-alpha-1</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>net.sf.json-lib</groupId>
        <artifactId>json-lib</artifactId>
        <version>2.3</version>
        <classifier>jdk15</classifier>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>net.sf.ezmorph</groupId>
        <artifactId>ezmorph</artifactId>
        <version>1.0.6</version>
    </dependency>  

    <dependency>
        <groupId>couchdb4j</groupId>
        <artifactId>couchdb4j</artifactId>
        <version>0.5.0-i386-1</version>
    </dependency>

    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20090211</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.simple-spring-memcached</groupId>
        <artifactId>spymemcached</artifactId>
        <version>2.8.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.0-beta1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.0-beta1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-flume-ng</artifactId>
        <version>2.0-alpha2</version>       
    </dependency>
</dependencies>

I don't know how to begin solving this. I have managed to get Flume working with my other servers no problem but it appears that Jetty will have none of it. Can someone offer any advice to get this working?

Was it helpful?

Solution

I've recently used jetty-6.1.26 with log4j2 in my project. It seems that you miss log4j2-jcl to bridge commons-logging from other packages, instead of excluding it. I could not start my project without it. You will need to define commons-logging.properties to use Log4j2 implementation and make sure it appears first in your class path.

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

log4j2 is still beta2 and has a known bug with commons-logging, I've found that it is fixed in beta3 but not sure when it will be released.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top