Reputation: 1327
We would like to make jetty use log4j configuration for logging. I am using embedded jetty within spring based on this tutorial. I am followed this documentation to include all required slf4j and log4j dependencies in classpath.
Basically I added jetty-logging.properties to classpath with following configuration.
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.Slf4Log
org.eclipse.jetty.LEVEL=INFO
I also have log4j.properties in classpath
I have following maven dependencies to include required jars.
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.log4j.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.maven.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>8.1.9.v20130131</version>
</dependency>
But when I start up the jetty server via spring, the log output is always logged to StdErr and it's not logging to log file I configured in log4j.properties. Am I missing anything? Is there any debugging I can turn on to troubleshoot ..? How can I get this to work?
Upvotes: 0
Views: 5090
Reputation: 4866
Though the answer to this question did help me find the answer, it took me a little bit more digging.
I was using Spring MVC with log4j. The following
public class LaunchServer {
private static final int SERVER_PORT = 8008;
public static void main(String[] args) throws Exception {
//Make sure you set the log before you start the server
Log.setLog(new Slf4jLog());
Server server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(SERVER_PORT);
server.addConnector(connector);
WebAppContext wac = new WebAppContext();
wac.setWar("war");
wac.setContextPath("/");
wac.setMaxFormContentSize(5242880);
wac.setMaxFormKeys(100000);
wac.setClassLoader(Thread.currentThread().getContextClassLoader());
server.setHandler(wac);
server.setStopAtShutdown(true);
server.start();
}
}
In my log4j2.xml file under the <Loggers>
I put
<Logger name="org.eclipse.jetty" level="debug" />
It worked well for me and avoided everything being logged to StdErr
Upvotes: 1