improved debug logging of request/response

This commit is contained in:
Greg Wilkins 2016-07-29 12:34:12 +10:00
parent 35c21d7ced
commit 23cb28e856
3 changed files with 27 additions and 21 deletions

View File

@ -34,6 +34,7 @@ import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.ConnectorStatistics;
import org.eclipse.jetty.server.DebugListener;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpChannel;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.LowResourceMonitor;
@ -47,6 +48,7 @@ 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.server.handler.StatisticsHandler;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
@ -166,7 +168,7 @@ public class LikeJettyXml
// === jetty-deploy.xml ===
DeploymentManager deployer = new DeploymentManager();
DebugListener debug = new DebugListener(System.out,true,true,true);
DebugListener debug = new DebugListener(System.err,true,true,true);
server.addBean(debug);
deployer.addLifeCycleBinding(new DebugListenerBinding(debug));
deployer.setContexts(contexts);

View File

@ -597,6 +597,11 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
fields.put(_connector.getServer().getDateField());
_request.setMetaData(request);
if (LOG.isDebugEnabled())
LOG.debug("REQUEST for {} on {}{}{} {} {}{}{}",request.getURIString(),this,System.lineSeparator(),
request.getMethod(),request.getURIString(),request.getVersion(),System.lineSeparator(),
request.getFields());
}
public boolean onContent(HttpInput.Content content)
@ -616,6 +621,9 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
public void onCompleted()
{
if (LOG.isDebugEnabled())
LOG.debug("COMPLETE for {} written={}",getRequest().getRequestURI(),getBytesWritten());
if (_requestLog!=null )
_requestLog.log(_request, _response);
@ -733,7 +741,9 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
{
_committedMetaData=info;
if (LOG.isDebugEnabled())
LOG.debug("Commit {} to {}",info,this);
LOG.debug("COMMIT for {} on {}{}{} {} {}{}{}",getRequest().getRequestURI(),this,System.lineSeparator(),
info.getStatus(),info.getReason(),info.getVersion(),System.lineSeparator(),
info.getFields());
}
public boolean isCommitted()

View File

@ -502,15 +502,14 @@ public class Server extends HandlerWrapper implements Attributes
* or after the entire request has been received (for short requests of known length), or
* on the dispatch of an async request.
*/
public void handle(HttpChannel connection) throws IOException, ServletException
public void handle(HttpChannel channel) throws IOException, ServletException
{
final String target=connection.getRequest().getPathInfo();
final Request request=connection.getRequest();
final Response response=connection.getResponse();
final String target=channel.getRequest().getPathInfo();
final Request request=channel.getRequest();
final Response response=channel.getResponse();
if (LOG.isDebugEnabled())
LOG.debug("{} on {}{}{} {} {}{}{}", request.getDispatcherType(), connection, System.lineSeparator(),
request.getMethod(), target, request.getProtocol(), System.lineSeparator(), request.getHttpFields());
LOG.debug("{} {} {} on {}", request.getDispatcherType(), request.getMethod(), target, channel);
if (HttpMethod.OPTIONS.is(request.getMethod()) || "*".equals(target))
{
@ -524,8 +523,7 @@ public class Server extends HandlerWrapper implements Attributes
handle(target, request, request, response);
if (LOG.isDebugEnabled())
LOG.debug("RESPONSE for {} h={}{}{} {}{}{}", target, request.isHandled(), System.lineSeparator(),
response.getStatus(), response.getReason(), System.lineSeparator(), response.getHttpFields());
LOG.debug("handled={} async={} committed={} on {}", request.isHandled(),request.isAsyncStarted(),response.isCommitted(),channel);
}
/* ------------------------------------------------------------ */
@ -541,12 +539,12 @@ public class Server extends HandlerWrapper implements Attributes
* or after the entire request has been received (for short requests of known length), or
* on the dispatch of an async request.
*/
public void handleAsync(HttpChannel connection) throws IOException, ServletException
public void handleAsync(HttpChannel channel) throws IOException, ServletException
{
final HttpChannelState state = connection.getRequest().getHttpChannelState();
final HttpChannelState state = channel.getRequest().getHttpChannelState();
final AsyncContextEvent event = state.getAsyncContextEvent();
final Request baseRequest=connection.getRequest();
final Request baseRequest=channel.getRequest();
final String path=event.getPath();
if (path!=null)
@ -566,14 +564,10 @@ public class Server extends HandlerWrapper implements Attributes
final HttpServletResponse response=(HttpServletResponse)event.getSuppliedResponse();
if (LOG.isDebugEnabled())
{
LOG.debug(request.getDispatcherType()+" "+request.getMethod()+" "+target+" on "+connection);
handle(target, baseRequest, request, response);
LOG.debug("RESPONSE "+target+" "+connection.getResponse().getStatus());
}
else
handle(target, baseRequest, request, response);
LOG.debug("{} {} {} on {}", request.getDispatcherType(), request.getMethod(), target, channel);
handle(target, baseRequest, request, response);
if (LOG.isDebugEnabled())
LOG.debug("handledAsync={} async={} committed={} on {}", channel.getRequest().isHandled(),request.isAsyncStarted(),response.isCommitted(),channel);
}
/* ------------------------------------------------------------ */