You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2011/05/29 00:43:43 UTC

svn commit: r1128790 - in /httpcomponents/httpcore/trunk: httpcore-contrib/src/main/java/org/apache/http/contrib/logging/ httpcore-nio/src/main/java/org/apache/http/impl/nio/ httpcore/src/main/java/org/apache/http/impl/

Author: olegk
Date: Sat May 28 22:43:42 2011
New Revision: 1128790

URL: http://svn.apache.org/viewvc?rev=1128790&view=rev
Log:
Improved #toString() methods of connection classes; improved wire / connection logging

Modified:
    httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
    httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
    httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java
    httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java
    httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
    httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/Wire.java
    httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java

Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingClientIOEventDispatch.java Sat May 28 22:43:42 2011
@@ -44,7 +44,7 @@ public class LoggingClientIOEventDispatc
     @Override
     protected NHttpClientIOTarget createConnection(final IOSession session) {
         return new LoggingNHttpClientConnection(
-            new LoggingIOSession(session, "client"),
+            new LoggingIOSession(session),
             createHttpResponseFactory(),
             this.allocator,
             this.params);

Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingIOSession.java Sat May 28 22:43:42 2011
@@ -32,7 +32,6 @@ import java.net.SocketAddress;
 import java.nio.ByteBuffer;
 import java.nio.channels.ByteChannel;
 import java.nio.channels.SelectionKey;
-import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -46,24 +45,20 @@ import org.apache.http.nio.reactor.Sessi
  */
 public class LoggingIOSession implements IOSession {
 
-    private static AtomicLong COUNT = new AtomicLong(0);
-
     private final Log log;
     private final Wire wirelog;
     private final IOSession session;
     private final ByteChannel channel;
-    private final String id;
 
-    public LoggingIOSession(final IOSession session, final String id) {
+    public LoggingIOSession(final IOSession session) {
         super();
         if (session == null) {
             throw new IllegalArgumentException("I/O session may not be null");
         }
         this.session = session;
         this.channel = new LoggingByteChannel();
-        this.id = id + "-" + COUNT.incrementAndGet();
         this.log = LogFactory.getLog(session.getClass());
-        this.wirelog = new Wire(LogFactory.getLog("org.apache.http.wire"));
+        this.wirelog = new Wire(LogFactory.getLog("org.apache.http.wire"), getId());
     }
 
     public ByteChannel channel() {
@@ -102,32 +97,29 @@ public class LoggingIOSession implements
     }
 
     public void setEventMask(int ops) {
+        this.session.setEventMask(ops);
         if (this.log.isDebugEnabled()) {
-            this.log.debug("I/O session " + this.id + " " + this.session + ": Set event mask "
-                    + formatOps(ops));
+            this.log.debug(getId() + " " + this.session + ": Event mask set " + formatOps(ops));
         }
-        this.session.setEventMask(ops);
     }
 
     public void setEvent(int op) {
+        this.session.setEvent(op);
         if (this.log.isDebugEnabled()) {
-            this.log.debug("I/O session " + this.id + " " + this.session + ": Set event "
-                    + formatOps(op));
+            this.log.debug(getId() + " " + this.session + ": Event set " + formatOps(op));
         }
-        this.session.setEvent(op);
     }
 
     public void clearEvent(int op) {
+        this.session.clearEvent(op);
         if (this.log.isDebugEnabled()) {
-            this.log.debug("I/O session " + this.id + " " + this.session + ": Clear event "
-                    + formatOps(op));
+            this.log.debug(getId() + " " + this.session + ": Event cleared " + formatOps(op));
         }
-        this.session.clearEvent(op);
     }
 
     public void close() {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("I/O session " + this.id + " " + this.session + ": Close");
+            this.log.debug(getId() + " " + this.session + ": Close");
         }
         this.session.close();
     }
@@ -142,7 +134,7 @@ public class LoggingIOSession implements
 
     public void shutdown() {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("I/O session " + this.id + " " + this.session + ": Shutdown");
+            this.log.debug(getId() + " " + this.session + ": Shutdown");
         }
         this.session.shutdown();
     }
@@ -153,8 +145,7 @@ public class LoggingIOSession implements
 
     public void setSocketTimeout(int timeout) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("I/O session " + this.id + " " + this.session + ": Set timeout "
-                    + timeout);
+            this.log.debug(getId() + " " + this.session + ": Set timeout " + timeout);
         }
         this.session.setSocketTimeout(timeout);
     }
@@ -177,26 +168,35 @@ public class LoggingIOSession implements
 
     public void setAttribute(final String name, final Object obj) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("I/O session " + this.id + " " + this.session + ": Set attribute "
-                    + name);
+            this.log.debug(getId() + " " + this.session + ": Set attribute " + name);
         }
         this.session.setAttribute(name, obj);
     }
 
     public Object removeAttribute(final String name) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("I/O session " + this.id + " " + this.session + ": Remove attribute "
-                    + name);
+            this.log.debug(getId() + " " + this.session + ": Remove attribute " + name);
         }
         return this.session.removeAttribute(name);
     }
 
+    private String getId() {
+        StringBuilder buf = new StringBuilder();
+        buf.append(getLocalAddress()).append("->").append(getRemoteAddress());
+        return buf.toString();
+    }
+
+    @Override
+    public String toString() {
+        return getId() + " " + this.session.toString();
+    }
+
     class LoggingByteChannel implements ByteChannel {
 
         public int read(final ByteBuffer dst) throws IOException {
             int bytesRead = session.channel().read(dst);
             if (log.isDebugEnabled()) {
-                log.debug("I/O session " + id + " " + session + ": " + bytesRead + " bytes read");
+                log.debug(getId() + " " + session + ": " + bytesRead + " bytes read");
             }
             if (bytesRead > 0 && wirelog.isEnabled()) {
                 ByteBuffer b = dst.duplicate();
@@ -211,7 +211,7 @@ public class LoggingIOSession implements
         public int write(final ByteBuffer src) throws IOException {
             int byteWritten = session.channel().write(src);
             if (log.isDebugEnabled()) {
-                log.debug("I/O session " + id + " " + session + ": " + byteWritten + " bytes written");
+                log.debug(getId() + " " + session + ": " + byteWritten + " bytes written");
             }
             if (byteWritten > 0 && wirelog.isEnabled()) {
                 ByteBuffer b = src.duplicate();
@@ -225,7 +225,7 @@ public class LoggingIOSession implements
 
         public void close() throws IOException {
             if (log.isDebugEnabled()) {
-                log.debug("I/O session " + id + " " + session + ": Channel close");
+                log.debug(getId() + " " + session + ": Channel close");
             }
             session.channel().close();
         }

Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java Sat May 28 22:43:42 2011
@@ -64,33 +64,41 @@ public class LoggingNHttpClientConnectio
 
     @Override
     public void close() throws IOException {
-        this.log.debug("Close connection");
+        if (this.log.isDebugEnabled()) {
+            this.log.debug(getId() + ": Close connection");
+        }
         super.close();
     }
 
     @Override
     public void shutdown() throws IOException {
-        this.log.debug("Shutdown connection");
+        if (this.log.isDebugEnabled()) {
+            this.log.debug(getId() + ": Shutdown connection");
+        }
         super.shutdown();
     }
 
     @Override
     public void submitRequest(final HttpRequest request) throws IOException, HttpException {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + this + ": "  + request.getRequestLine().toString());
+            this.log.debug(getId() + ": "  + request.getRequestLine().toString());
         }
         super.submitRequest(request);
     }
 
     @Override
     public void consumeInput(final NHttpClientHandler handler) {
-        this.log.debug("Consume input");
+        if (this.log.isDebugEnabled()) {
+            this.log.debug(getId() + ": Consume input");
+        }
         super.consumeInput(handler);
     }
 
     @Override
     public void produceOutput(final NHttpClientHandler handler) {
-        this.log.debug("Produce output");
+        if (this.log.isDebugEnabled()) {
+            this.log.debug(getId() + ": Produce output");
+        }
         super.produceOutput(handler);
     }
 
@@ -111,6 +119,19 @@ public class LoggingNHttpClientConnectio
                 super.createResponseParser(buffer, responseFactory, params));
     }
 
+    private String getId() {
+        StringBuilder buf = new StringBuilder();
+        buf.append(getLocalAddress()).append(":").append(getLocalPort())
+            .append("->")
+            .append(getRemoteAddress()).append(":").append(getRemotePort());
+        return buf.toString();
+    }
+
+    @Override
+    public String toString() {
+        return getId();
+    }
+
     class LoggingNHttpMessageWriter implements NHttpMessageWriter<HttpRequest> {
 
         private final NHttpMessageWriter<HttpRequest> writer;
@@ -126,10 +147,10 @@ public class LoggingNHttpClientConnectio
 
         public void write(final HttpRequest message) throws IOException, HttpException {
             if (message != null && headerlog.isDebugEnabled()) {
-                headerlog.debug(">> " + message.getRequestLine().toString());
+                headerlog.debug(getId() + " >> " + message.getRequestLine().toString());
                 Header[] headers = message.getAllHeaders();
                 for (int i = 0; i < headers.length; i++) {
-                    headerlog.debug(">> " + headers[i].toString());
+                    headerlog.debug(getId() + " >> " + headers[i].toString());
                 }
             }
             this.writer.write(message);
@@ -157,10 +178,10 @@ public class LoggingNHttpClientConnectio
         public HttpResponse parse() throws IOException, HttpException {
             HttpResponse message = this.parser.parse();
             if (message != null && headerlog.isDebugEnabled()) {
-                headerlog.debug("<< " + message.getStatusLine().toString());
+                headerlog.debug(getId() + " << " + message.getStatusLine().toString());
                 Header[] headers = message.getAllHeaders();
                 for (int i = 0; i < headers.length; i++) {
-                    headerlog.debug("<< " + headers[i].toString());
+                    headerlog.debug(getId() + " << " + headers[i].toString());
                 }
             }
             return message;

Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java Sat May 28 22:43:42 2011
@@ -62,73 +62,73 @@ public class LoggingNHttpClientHandler i
 
     public void connected(final NHttpClientConnection conn, final Object attachment) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Connected (" + attachment + ")");
+            this.log.debug(conn + ": Connected (" + attachment + ")");
         }
         this.handler.connected(conn, attachment);
     }
 
     public void closed(final NHttpClientConnection conn) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Closed");
+            this.log.debug(conn + ": Closed");
         }
         this.handler.closed(conn);
     }
 
     public void exception(final NHttpClientConnection conn, final IOException ex) {
-        this.log.error("HTTP connection " + conn + ": " + ex.getMessage(), ex);
+        this.log.error(conn + ": " + ex.getMessage(), ex);
         this.handler.exception(conn, ex);
     }
 
     public void exception(final NHttpClientConnection conn, final HttpException ex) {
-        this.log.error("HTTP connection " + conn + ": " + ex.getMessage(), ex);
+        this.log.error(conn + ": " + ex.getMessage(), ex);
         this.handler.exception(conn, ex);
     }
 
     public void requestReady(final NHttpClientConnection conn) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Request ready");
+            this.log.debug(conn + ": Request ready");
         }
         this.handler.requestReady(conn);
     }
 
     public void outputReady(final NHttpClientConnection conn, final ContentEncoder encoder) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Output ready");
+            this.log.debug(conn + ": Output ready");
         }
         this.handler.outputReady(conn, encoder);
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Content encoder " + encoder);
+            this.log.debug(conn + ": Content encoder " + encoder);
         }
     }
 
     public void responseReceived(final NHttpClientConnection conn) {
         HttpResponse response = conn.getHttpResponse();
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": " + response.getStatusLine());
+            this.log.debug(conn + ": " + response.getStatusLine());
         }
         this.handler.responseReceived(conn);
         if (this.headerlog.isDebugEnabled()) {
-            this.headerlog.debug("<< " + response.getStatusLine().toString());
+            this.headerlog.debug(conn + " << " + response.getStatusLine().toString());
             Header[] headers = response.getAllHeaders();
             for (int i = 0; i < headers.length; i++) {
-                this.headerlog.debug("<< " + headers[i].toString());
+                this.headerlog.debug(conn + " << " + headers[i].toString());
             }
         }
     }
 
     public void inputReady(final NHttpClientConnection conn, final ContentDecoder decoder) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Input ready");
+            this.log.debug(conn + ": Input ready");
         }
         this.handler.inputReady(conn, decoder);
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Content decoder " + decoder);
+            this.log.debug(conn + ": Content decoder " + decoder);
         }
     }
 
     public void timeout(final NHttpClientConnection conn) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Timeout");
+            this.log.debug(conn + ": Timeout");
         }
         this.handler.timeout(conn);
     }

Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java Sat May 28 22:43:42 2011
@@ -64,33 +64,41 @@ public class LoggingNHttpServerConnectio
 
     @Override
     public void close() throws IOException {
-        this.log.debug("Close connection");
+        if (this.log.isDebugEnabled()) {
+            this.log.debug(getId() + ": Close connection");
+        }
         super.close();
     }
 
     @Override
     public void shutdown() throws IOException {
-        this.log.debug("Shutdown connection");
+        if (this.log.isDebugEnabled()) {
+            this.log.debug(getId() + ": Shutdown connection");
+        }
         super.shutdown();
     }
 
     @Override
     public void submitResponse(final HttpResponse response) throws IOException, HttpException {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + this + ": "  + response.getStatusLine().toString());
+            this.log.debug(getId() + ": "  + response.getStatusLine().toString());
         }
         super.submitResponse(response);
     }
 
     @Override
     public void consumeInput(final NHttpServiceHandler handler) {
-        this.log.debug("Consume input");
+        if (this.log.isDebugEnabled()) {
+            this.log.debug(getId() + ": Consume input");
+        }
         super.consumeInput(handler);
     }
 
     @Override
     public void produceOutput(final NHttpServiceHandler handler) {
-        this.log.debug("Produce output");
+        if (this.log.isDebugEnabled()) {
+            this.log.debug(getId() + ": Produce output");
+        }
         super.produceOutput(handler);
     }
 
@@ -111,6 +119,19 @@ public class LoggingNHttpServerConnectio
                 super.createRequestParser(buffer, requestFactory, params));
     }
 
+    private String getId() {
+        StringBuilder buf = new StringBuilder();
+        buf.append(getLocalAddress()).append(":").append(getLocalPort())
+            .append("->")
+            .append(getRemoteAddress()).append(":").append(getRemotePort());
+        return buf.toString();
+    }
+
+    @Override
+    public String toString() {
+        return getId();
+    }
+
     class LoggingNHttpMessageWriter implements NHttpMessageWriter<HttpResponse> {
 
         private final NHttpMessageWriter<HttpResponse> writer;
@@ -126,10 +147,10 @@ public class LoggingNHttpServerConnectio
 
         public void write(final HttpResponse message) throws IOException, HttpException {
             if (message != null && headerlog.isDebugEnabled()) {
-                headerlog.debug("<< " + message.getStatusLine().toString());
+                headerlog.debug(getId() + " << " + message.getStatusLine().toString());
                 Header[] headers = message.getAllHeaders();
                 for (int i = 0; i < headers.length; i++) {
-                    headerlog.debug("<< " + headers[i].toString());
+                    headerlog.debug(getId() + " << " + headers[i].toString());
                 }
             }
             this.writer.write(message);
@@ -157,10 +178,10 @@ public class LoggingNHttpServerConnectio
         public HttpRequest parse() throws IOException, HttpException {
             HttpRequest message = this.parser.parse();
             if (message != null && headerlog.isDebugEnabled()) {
-                headerlog.debug(">> " + message.getRequestLine().toString());
+                headerlog.debug(getId() + " >> " + message.getRequestLine().toString());
                 Header[] headers = message.getAllHeaders();
                 for (int i = 0; i < headers.length; i++) {
-                    headerlog.debug(">> " + headers[i].toString());
+                    headerlog.debug(getId() + " >> " + headers[i].toString());
                 }
             }
             return message;

Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java Sat May 28 22:43:42 2011
@@ -62,73 +62,73 @@ public class LoggingNHttpServiceHandler 
 
     public void connected(final NHttpServerConnection conn) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Connected");
+            this.log.debug(conn + ": Connected");
         }
         this.handler.connected(conn);
     }
 
     public void closed(final NHttpServerConnection conn) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Closed");
+            this.log.debug(conn + ": Closed");
         }
         this.handler.closed(conn);
     }
 
     public void exception(final NHttpServerConnection conn, final IOException ex) {
-        this.log.error("HTTP connection " + conn + ": " + ex.getMessage(), ex);
+        this.log.error(conn + ": " + ex.getMessage(), ex);
         this.handler.exception(conn, ex);
     }
 
     public void exception(final NHttpServerConnection conn, final HttpException ex) {
-        this.log.error("HTTP connection " + conn + ": " + ex.getMessage(), ex);
+        this.log.error(conn + ": " + ex.getMessage(), ex);
         this.handler.exception(conn, ex);
     }
 
     public void requestReceived(final NHttpServerConnection conn) {
         HttpRequest request = conn.getHttpRequest();
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": " + request.getRequestLine());
+            this.log.debug(conn + ": " + request.getRequestLine());
         }
         this.handler.requestReceived(conn);
         if (this.headerlog.isDebugEnabled()) {
-            this.headerlog.debug(">> " + request.getRequestLine().toString());
+            this.headerlog.debug(conn + " >> " + request.getRequestLine().toString());
             Header[] headers = request.getAllHeaders();
             for (int i = 0; i < headers.length; i++) {
-                this.headerlog.debug(">> " + headers[i].toString());
+                this.headerlog.debug(conn + " >> " + headers[i].toString());
             }
         }
     }
 
     public void outputReady(final NHttpServerConnection conn, final ContentEncoder encoder) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Output ready");
+            this.log.debug(conn + ": Output ready");
         }
         this.handler.outputReady(conn, encoder);
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Content encoder " + encoder);
+            this.log.debug(conn + ": Content encoder " + encoder);
         }
     }
 
     public void responseReady(final NHttpServerConnection conn) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Response ready");
+            this.log.debug(conn + ": Response ready");
         }
         this.handler.responseReady(conn);
     }
 
     public void inputReady(final NHttpServerConnection conn, final ContentDecoder decoder) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Input ready");
+            this.log.debug(conn + ": Input ready");
         }
         this.handler.inputReady(conn, decoder);
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Content decoder " + decoder);
+            this.log.debug(conn + ": Content decoder " + decoder);
         }
     }
 
     public void timeout(final NHttpServerConnection conn) {
         if (this.log.isDebugEnabled()) {
-            this.log.debug("HTTP connection " + conn + ": Timeout");
+            this.log.debug(conn + ": Timeout");
         }
         this.handler.timeout(conn);
     }

Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingServerIOEventDispatch.java Sat May 28 22:43:42 2011
@@ -44,7 +44,7 @@ public class LoggingServerIOEventDispatc
     @Override
     protected NHttpServerIOTarget createConnection(final IOSession session) {
         return new LoggingNHttpServerConnection(
-            new LoggingIOSession(session, "server"),
+            new LoggingIOSession(session),
             createHttpRequestFactory(),
             this.allocator,
             this.params);

Modified: httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/Wire.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/Wire.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/Wire.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-contrib/src/main/java/org/apache/http/contrib/logging/Wire.java Sat May 28 22:43:42 2011
@@ -33,10 +33,12 @@ import org.apache.commons.logging.Log;
 class Wire {
 
     private final Log log;
+    private final String id;
 
-    public Wire(final Log log) {
+    public Wire(final Log log, final String id) {
         super();
         this.log = log;
+        this.id = id;
     }
 
     private void wire(final String header, final byte[] b, int pos, int off) {
@@ -49,7 +51,7 @@ class Wire {
                     buffer.append("[\\n]\"");
                     buffer.insert(0, "\"");
                     buffer.insert(0, header);
-                    this.log.debug(buffer.toString());
+                    this.log.debug(this.id + " " + buffer.toString());
                     buffer.setLength(0);
             } else if ((ch < 32) || (ch > 127)) {
                 buffer.append("[0x");
@@ -63,7 +65,7 @@ class Wire {
             buffer.append('\"');
             buffer.insert(0, '\"');
             buffer.insert(0, header);
-            this.log.debug(buffer.toString());
+            this.log.debug(this.id + " " + buffer.toString());
         }
     }
 

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/main/java/org/apache/http/impl/nio/NHttpConnectionBase.java Sat May 28 22:43:42 2011
@@ -423,14 +423,11 @@ public class NHttpConnectionBase
 
     @Override
     public String toString() {
-        StringBuilder buffer = new StringBuilder();
-        buffer.append("[");
-        buffer.append(this.remote);
-        if (this.status == CLOSED) {
-            buffer.append("(closed)");
-        }
-        buffer.append("]");
-        return buffer.toString();
+        StringBuilder buf = new StringBuilder();
+        buf.append(this.session.getLocalAddress())
+            .append("->")
+            .append(this.session.getRemoteAddress());
+        return buf.toString();
     }
 
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultHttpClientConnection.java Sat May 28 22:43:42 2011
@@ -76,17 +76,4 @@ public class DefaultHttpClientConnection
         super.bind(socket, params);
     }
 
-    @Override
-    public String toString() {
-        StringBuilder buffer = new StringBuilder();
-        buffer.append("[");
-        if (isOpen()) {
-            buffer.append(getRemotePort());
-        } else {
-            buffer.append("closed");
-        }
-        buffer.append("]");
-        return buffer.toString();
-    }
-
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/DefaultHttpServerConnection.java Sat May 28 22:43:42 2011
@@ -74,17 +74,4 @@ public class DefaultHttpServerConnection
         super.bind(socket, params);
     }
 
-    @Override
-    public String toString() {
-        StringBuilder buffer = new StringBuilder();
-        buffer.append("[");
-        if (isOpen()) {
-            buffer.append(getRemotePort());
-        } else {
-            buffer.append("closed");
-        }
-        buffer.append("]");
-        return buffer.toString();
-    }
-
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpClientConnection.java Sat May 28 22:43:42 2011
@@ -261,4 +261,17 @@ public class SocketHttpClientConnection
         }
     }
 
+    @Override
+    public String toString() {
+        StringBuilder buffer = new StringBuilder();
+        buffer.append("[");
+        if (isOpen()) {
+            buffer.append(getRemotePort());
+        } else {
+            buffer.append("closed");
+        }
+        buffer.append("]");
+        return buffer.toString();
+    }
+
 }

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java?rev=1128790&r1=1128789&r2=1128790&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/impl/SocketHttpServerConnection.java Sat May 28 22:43:42 2011
@@ -259,4 +259,17 @@ public class SocketHttpServerConnection 
         }
     }
 
+    @Override
+    public String toString() {
+        StringBuilder buf = new StringBuilder();
+        if (this.socket != null) {
+            buf.append(this.socket.getLocalSocketAddress())
+            .append("->")
+            .append(this.socket.getRemoteSocketAddress());
+        } else {
+            buf.append("no socket");
+        }
+        return buf.toString();
+    }
+
 }