add slf4j handler to log web-server log
@@ -21,6 +21,8 @@ package org.apache.pulsar.functions.worker.rest;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
+import java.util.TimeZone;
+
import javax.servlet.DispatcherType;
import lombok.extern.slf4j.Slf4j;
import org.apache.pulsar.broker.web.AuthenticationFilter;
@@ -32,6 +34,7 @@ import org.apache.pulsar.functions.worker.WorkerService;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.Slf4jRequestLog;
import java.net.BindException;
import java.net.URI;
@@ -39,6 +42,7 @@ import java.security.GeneralSecurityException;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
+import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
@@ -98,10 +102,19 @@ public class WorkerServer {
newServletContextHandler("/admin/v2", new ResourceConfig(Resources.getApiResources()), workerService));
handlers.add(newServletContextHandler("/", new ResourceConfig(Resources.getRootResources()), workerService));
+ RequestLogHandler requestLogHandler = new RequestLogHandler();
+ Slf4jRequestLog requestLog = new Slf4jRequestLog();
+ requestLog.setExtended(true);
+ requestLog.setLogTimeZone(TimeZone.getDefault().getID());
+ requestLog.setLogLatency(true);
+ requestLogHandler.setRequestLog(requestLog);
+ handlers.add(0, new ContextHandlerCollection());
+ handlers.add(requestLogHandler);
+
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(handlers.toArray(new Handler[handlers.size()]));
HandlerCollection handlerCollection = new HandlerCollection();
- handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler() });
+ handlerCollection.setHandlers(new Handler[] { contexts, new DefaultHandler(), requestLogHandler });
server.setHandler(handlerCollection);
if (this.workerConfig.isTlsEnabled()) {
