Author: rgodfrey
Date: Fri Apr 11 22:48:38 2014
New Revision: 1586792

URL: http://svn.apache.org/r1586792
Log:
QPID-5683 : [Java Broker] Make the AMQP 1.0 protocol logging available through 
log4j (like the rest of the broker) rather than java.logging

Modified:
    
qpid/trunk/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java
    
qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0_SASL.java

Modified: 
qpid/trunk/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java?rev=1586792&r1=1586791&r2=1586792&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java
 (original)
+++ 
qpid/trunk/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java
 Fri Apr 11 22:48:38 2014
@@ -21,37 +21,50 @@
 
 package org.apache.qpid.amqp_1_0.transport;
 
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.TimeoutException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.security.sasl.SaslException;
+import javax.security.sasl.SaslServer;
 
 import org.apache.qpid.amqp_1_0.codec.DescribedTypeConstructorRegistry;
 import org.apache.qpid.amqp_1_0.codec.ValueWriter;
 import org.apache.qpid.amqp_1_0.framing.AMQFrame;
 import org.apache.qpid.amqp_1_0.framing.SASLFrame;
-import org.apache.qpid.amqp_1_0.type.*;
+import org.apache.qpid.amqp_1_0.type.Binary;
+import org.apache.qpid.amqp_1_0.type.FrameBody;
+import org.apache.qpid.amqp_1_0.type.SaslFrameBody;
+import org.apache.qpid.amqp_1_0.type.Symbol;
+import org.apache.qpid.amqp_1_0.type.UnsignedInteger;
+import org.apache.qpid.amqp_1_0.type.UnsignedShort;
+import org.apache.qpid.amqp_1_0.type.codec.AMQPDescribedTypeRegistry;
 import org.apache.qpid.amqp_1_0.type.security.SaslChallenge;
 import org.apache.qpid.amqp_1_0.type.security.SaslCode;
 import org.apache.qpid.amqp_1_0.type.security.SaslInit;
 import org.apache.qpid.amqp_1_0.type.security.SaslMechanisms;
 import org.apache.qpid.amqp_1_0.type.security.SaslOutcome;
 import org.apache.qpid.amqp_1_0.type.security.SaslResponse;
-import org.apache.qpid.amqp_1_0.type.transport.*;
+import org.apache.qpid.amqp_1_0.type.transport.Attach;
+import org.apache.qpid.amqp_1_0.type.transport.Begin;
+import org.apache.qpid.amqp_1_0.type.transport.Close;
+import org.apache.qpid.amqp_1_0.type.transport.ConnectionError;
+import org.apache.qpid.amqp_1_0.type.transport.Detach;
+import org.apache.qpid.amqp_1_0.type.transport.Disposition;
+import org.apache.qpid.amqp_1_0.type.transport.End;
 import org.apache.qpid.amqp_1_0.type.transport.Error;
-import org.apache.qpid.amqp_1_0.type.codec.AMQPDescribedTypeRegistry;
-
-import javax.security.sasl.SaslException;
-import javax.security.sasl.SaslServer;
-
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.charset.Charset;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.concurrent.TimeoutException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+import org.apache.qpid.amqp_1_0.type.transport.Flow;
+import org.apache.qpid.amqp_1_0.type.transport.Open;
+import org.apache.qpid.amqp_1_0.type.transport.Transfer;
 
 
 public class ConnectionEndpoint implements 
DescribedTypeConstructorRegistry.Source, ValueWriter.Registry.Source,
@@ -718,13 +731,43 @@ public class ConnectionEndpoint implemen
         }
     }
 
-    private final Logger _logger = Logger.getLogger("FRM");
+    public static interface FrameReceiptLogger
+    {
+        boolean isEnabled();
+        void received(final SocketAddress remoteAddress, short channel, Object 
frame);
+    }
+
+
+
+    private FrameReceiptLogger _logger =
+            new FrameReceiptLogger()
+            {
+                Logger _underlying = Logger.getLogger("FRM");
+
+                @Override
+                public boolean isEnabled()
+                {
+                    return _underlying.isLoggable(Level.FINE);
+                }
+
+                @Override
+                public void received(final SocketAddress remoteAddress, final 
short channel, final Object frame)
+                {
+                    _underlying.fine("RECV[" + remoteAddress + "|" + channel + 
"] : " + frame);
+                }
+
+            };
+
+    public void setLogger(final FrameReceiptLogger logger)
+    {
+        _logger = logger;
+    }
 
     public synchronized void receive(final short channel, final Object frame)
     {
-        if (_logger.isLoggable(Level.FINE))
+        if (_logger.isEnabled())
         {
-            _logger.fine("RECV[" + _remoteAddress + "|" + channel + "] : " + 
frame);
+            _logger.received(_remoteAddress, channel, frame);
         }
         if (frame instanceof FrameBody)
         {

Modified: 
qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0_SASL.java
URL: 
http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0_SASL.java?rev=1586792&r1=1586791&r2=1586792&view=diff
==============================================================================
--- 
qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0_SASL.java
 (original)
+++ 
qpid/trunk/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0_SASL.java
 Fri Apr 11 22:48:38 2014
@@ -28,24 +28,26 @@ import java.security.Principal;
 import java.security.PrivilegedAction;
 import java.util.LinkedHashMap;
 import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
+
 import javax.security.auth.Subject;
 import javax.security.sasl.SaslException;
 import javax.security.sasl.SaslServer;
+
+import org.apache.log4j.Logger;
+
 import org.apache.qpid.amqp_1_0.codec.FrameWriter;
 import org.apache.qpid.amqp_1_0.codec.ProtocolHandler;
 import org.apache.qpid.amqp_1_0.framing.AMQFrame;
 import org.apache.qpid.amqp_1_0.framing.OversizeFrameException;
 import org.apache.qpid.amqp_1_0.framing.SASLFrameHandler;
-import org.apache.qpid.amqp_1_0.transport.SaslServerProvider;
 import org.apache.qpid.amqp_1_0.transport.ConnectionEndpoint;
 import org.apache.qpid.amqp_1_0.transport.Container;
 import org.apache.qpid.amqp_1_0.transport.FrameOutputHandler;
+import org.apache.qpid.amqp_1_0.transport.SaslServerProvider;
 import org.apache.qpid.amqp_1_0.type.Binary;
 import org.apache.qpid.amqp_1_0.type.FrameBody;
 import org.apache.qpid.amqp_1_0.type.Symbol;
-import org.apache.qpid.amqp_1_0.type.transport.*;
+import org.apache.qpid.amqp_1_0.type.transport.AmqpError;
 import org.apache.qpid.amqp_1_0.type.transport.Error;
 import org.apache.qpid.common.QpidProperties;
 import org.apache.qpid.common.ServerPropertyNames;
@@ -185,7 +187,20 @@ public class ProtocolEngine_1_0_0_SASL i
 
         SubjectCreator subjectCreator = 
_broker.getSubjectCreator(getLocalAddress());
         _endpoint = new ConnectionEndpoint(container, 
asSaslServerProvider(subjectCreator));
+        _endpoint.setLogger(new ConnectionEndpoint.FrameReceiptLogger()
+        {
+            @Override
+            public boolean isEnabled()
+            {
+                return FRAME_LOGGER.isDebugEnabled();
+            }
 
+            @Override
+            public void received(final SocketAddress remoteAddress, final 
short channel, final Object frame)
+            {
+                FRAME_LOGGER.debug("RECV[" + remoteAddress + "|" + channel + 
"] : " + frame);
+            }
+        });
         Map<Symbol,Object> serverProperties = new LinkedHashMap<Symbol, 
Object>();
         serverProperties.put(Symbol.valueOf(ServerPropertyNames.PRODUCT), 
QpidProperties.getProductName());
         serverProperties.put(Symbol.valueOf(ServerPropertyNames.VERSION), 
QpidProperties.getReleaseVersion());
@@ -196,6 +211,7 @@ public class ProtocolEngine_1_0_0_SASL i
 
         _endpoint.setRemoteAddress(getRemoteAddress());
         _connection = new Connection_1_0(_broker, _endpoint, _connectionId, 
_port, _transport, subjectCreator);
+
         _endpoint.setConnectionEventListener(_connection);
         _endpoint.setFrameOutputHandler(this);
         _endpoint.setSaslFrameOutput(this);
@@ -262,13 +278,13 @@ public class ProtocolEngine_1_0_0_SASL i
         try
         {
             _lastReadTime = System.currentTimeMillis();
-            if(RAW_LOGGER.isLoggable(Level.FINE))
+            if(RAW_LOGGER.isDebugEnabled())
             {
                 ByteBuffer dup = msg.duplicate();
                 byte[] data = new byte[dup.remaining()];
                 dup.get(data);
                 Binary bin = new Binary(data);
-                RAW_LOGGER.fine("RECV[" + getRemoteAddress() + "] : " + 
bin.toString());
+                RAW_LOGGER.debug("RECV[" + getRemoteAddress() + "] : " + 
bin.toString());
             }
             _readBytes += msg.remaining();
             switch(_state)
@@ -454,9 +470,14 @@ public class ProtocolEngine_1_0_0_SASL i
         synchronized (_sendLock)
         {
             _lastWriteTime = System.currentTimeMillis();
-            if (FRAME_LOGGER.isLoggable(Level.FINE))
+            if (FRAME_LOGGER.isDebugEnabled())
             {
-                FRAME_LOGGER.fine("SEND[" + getRemoteAddress() + "|" + 
amqFrame.getChannel() + "] : " + amqFrame.getFrameBody());
+                FRAME_LOGGER.debug("SEND["
+                                   + getRemoteAddress()
+                                   + "|"
+                                   + amqFrame.getChannel()
+                                   + "] : "
+                                   + amqFrame.getFrameBody());
             }
 
             _frameWriter.setValue(amqFrame);
@@ -472,13 +493,13 @@ public class ProtocolEngine_1_0_0_SASL i
             dup.flip();
             _writtenBytes += dup.limit();
 
-            if (RAW_LOGGER.isLoggable(Level.FINE))
+            if (RAW_LOGGER.isDebugEnabled())
             {
                 ByteBuffer dup2 = dup.duplicate();
                 byte[] data = new byte[dup2.remaining()];
                 dup2.get(data);
                 Binary bin = new Binary(data);
-                RAW_LOGGER.fine("SEND[" + getRemoteAddress() + "] : " + 
bin.toString());
+                RAW_LOGGER.debug("SEND[" + getRemoteAddress() + "] : " + 
bin.toString());
             }
 
             _sender.send(dup);



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to