I have a webapp running on Jetty 9.3.6 in ${jetty.base}
which is set to /opt/mybase/
. My webapp uses slf4j
and I use log4j
as the actual logging framework, so the logging statements in my webapp source looks like this:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SillyClass
{
private static final Logger log = LoggerFactory.getLogger (SillyClass.class.getName ());
...
public static void foo ()
{
if (error ())
{
log.error ("ERROR");
}
else
{
log.info ("NOT an error");
}
}
...
}
And in my gradle build file, I did this:
dependencies {
...
compile 'org.slf4j:slf4j-api:1.7.12'
compile 'org.slf4j:slf4j-log4j12:1.7.12'
compile 'log4j:log4j:1.2.17'
...
}
This configuration works quite well for another (non-Jetty, non-webapp) Java project which uses the same logging framework; I can use ${project.home}/src/main/resources/log4j.properties
to control the output of the log.
Anyway, when I moved to Jetty, I followed the instructions here to the dot; but as soon as I did that, I hit the multiple-bindings error. To correct that, I removed the slf4j
references in my gradle build file, but that resulted in the error:
java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/eclipse/jetty/webapp/WebAppClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/eclipse/jetty/start/Classpath$Loader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
I then removed all references to slf4j
and log4j
(commented out the three lines I show in my build.gradle
above), but the error I see is still the same. What am I doing wrong?
My /opt/mybase/resources/log4j.properties
file:
log4j.rootLogger=TRACE, FILE
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=/opt/mybase/logs/jetty.log
log4j.appender.FILE.Append=false
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern= %d{dd MMM yyyy HH:mm:ss.SSS} %l %m%n
Any help is appreciated.