users@jersey.java.net

Re: [Jersey] log HTTP exchanges

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 19 Jan 2009 18:03:20 +0100

On Jan 19, 2009, at 5:53 PM, Vasiliy Baranov wrote:

> Hi,
>
> With Jersey, is it possible to fully log (e.g. via
> java.util.logging) all HTTP requests and responses taking place?
> Like what you get with commons-httpclient when you say:
>
> -
> Dorg
> .apache
> .commons.logging.Log=org.apache.commons.logging.impl.SimpleLog \
> -Dorg.apache.commons.logging.simplelog.showdatetime=true \
> -Dorg.apache.commons.logging.simplelog.log.httpclient.wire=debug
>
> I can see sun.net.www.protocol.http.HttpURLConnection logging
> message headers, but that is not enough in my case.
>

Do you want to log on the client side or the server side?

I will presuming it is the client side. You can add the following
LoggingFilter [1] to the Client.

   Client c = ...
   c.addFilter(new LoggingFilter());

If you want to be particular you can add a LoggingFilter instance to a
WebResource instead.

It does not use JDK logging thought, by default it prints out to the
System.out but you can pass in a PrintStream instance on construction.
Perhaps it should be changed to utilize logging?

Paul.

[1] https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0/api/jersey/com/sun/jersey/api/client/filter/LoggingFilter.html