activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1495057 - in /activemq/trunk/activemq-amqp/src: main/java/org/apache/activemq/transport/amqp/ test/java/org/apache/activemq/transport/amqp/joram/ test/resources/
Date Thu, 20 Jun 2013 15:43:45 GMT
Author: chirino
Date: Thu Jun 20 15:43:44 2013
New Revision: 1495057

URL: http://svn.apache.org/r1495057
Log:
Improve how trace logging is handled in the AMQP transport.

Modified:
    activemq/trunk/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpProtocolConverter.java
    activemq/trunk/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpTransportFilter.java
    activemq/trunk/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/joram/ActiveMQAdmin.java
    activemq/trunk/activemq-amqp/src/test/resources/log4j.properties

Modified: activemq/trunk/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpProtocolConverter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpProtocolConverter.java?rev=1495057&r1=1495056&r2=1495057&view=diff
==============================================================================
--- activemq/trunk/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpProtocolConverter.java
(original)
+++ activemq/trunk/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpProtocolConverter.java
Thu Jun 20 15:43:44 2013
@@ -102,7 +102,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 class AmqpProtocolConverter {
-
+    static final Logger TRACE_FRAMES = AmqpTransportFilter.TRACE_FRAMES;
     public static final EnumSet<EndpointState> UNINITIALIZED_SET = EnumSet.of(EndpointState.UNINITIALIZED);
     public static final EnumSet<EndpointState> INITIALIZED_SET = EnumSet.complementOf(UNINITIALIZED_SET);
     public static final EnumSet<EndpointState> ACTIVE_STATE = EnumSet.of(EndpointState.ACTIVE);
@@ -126,27 +126,32 @@ class AmqpProtocolConverter {
     public AmqpProtocolConverter(AmqpTransport transport, BrokerContext brokerContext) {
         this.amqpTransport = transport;
         this.protonTransport.bind(this.protonConnection);
-        if (transport.isTrace()) {
+        updateTracer();
+    }
+
+    void updateTracer() {
+        if (amqpTransport.isTrace()) {
             this.protonTransport.setProtocolTracer(new ProtocolTracer() {
                 @Override
                 public void receivedFrame(TransportFrame transportFrame) {
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug(String.format("%s | RECV: %s",
-                            amqpTransport.getRemoteAddress(), transportFrame.getBody()));
+                    if (TRACE_FRAMES.isTraceEnabled()) {
+                        TRACE_FRAMES.trace(String.format("%s | RECV: %s",
+                            AmqpProtocolConverter.this.amqpTransport.getRemoteAddress(),
transportFrame.getBody()));
                     }
                 }
 
                 @Override
                 public void sentFrame(TransportFrame transportFrame) {
-                    if (LOG.isDebugEnabled()) {
-                        LOG.debug(String.format("%s | SENT: %s",
-                            amqpTransport.getRemoteAddress(), transportFrame.getBody()));
+                    if (TRACE_FRAMES.isTraceEnabled()) {
+                        TRACE_FRAMES.trace(String.format("%s | SENT: %s",
+                            AmqpProtocolConverter.this.amqpTransport.getRemoteAddress(),
transportFrame.getBody()));
                     }
                 }
             });
         }
     }
 
+
     void pumpProtonToSocket() {
         try {
             int size = 1024 * 64;

Modified: activemq/trunk/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpTransportFilter.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpTransportFilter.java?rev=1495057&r1=1495056&r2=1495057&view=diff
==============================================================================
--- activemq/trunk/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpTransportFilter.java
(original)
+++ activemq/trunk/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/AmqpTransportFilter.java
Thu Jun 20 15:43:44 2013
@@ -39,7 +39,8 @@ import java.security.cert.X509Certificat
  */
 public class AmqpTransportFilter extends TransportFilter implements AmqpTransport {
     private static final Logger LOG = LoggerFactory.getLogger(AmqpTransportFilter.class);
-    private static final Logger TRACE = LoggerFactory.getLogger(AmqpTransportFilter.class.getPackage().getName()
+ ".AMQPIO");
+    static final Logger TRACE_BYTES = LoggerFactory.getLogger(AmqpTransportFilter.class.getPackage().getName()
+ ".BYTES");
+    static final Logger TRACE_FRAMES = LoggerFactory.getLogger(AmqpTransportFilter.class.getPackage().getName()
+ ".FRAMES");
     private final AmqpProtocolConverter protocolConverter;
 //    private AmqpInactivityMonitor monitor;
     private AmqpWireFormat wireFormat;
@@ -86,8 +87,8 @@ public class AmqpTransportFilter extends
 
     public void onCommand(Object command) {
         try {
-            if (trace) {
-                TRACE.trace("Received: \n" + command);
+            if (trace && TRACE_BYTES.isTraceEnabled()) {
+                TRACE_BYTES.trace("Received: \n" + command);
             }
             protocolConverter.lock.lock();
             try {
@@ -112,8 +113,8 @@ public class AmqpTransportFilter extends
 
     public void sendToAmqp(Object command) throws IOException {
         assert protocolConverter.lock.isHeldByCurrentThread();
-        if (trace) {
-            TRACE.trace("Sending: \n" + command);
+        if (trace && TRACE_BYTES.isTraceEnabled()) {
+            TRACE_BYTES.trace("Sending: \n" + command);
         }
         Transport n = next;
         if (n != null) {
@@ -138,6 +139,7 @@ public class AmqpTransportFilter extends
 
     public void setTrace(boolean trace) {
         this.trace = trace;
+        this.protocolConverter.updateTracer();
     }
 
 //    @Override

Modified: activemq/trunk/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/joram/ActiveMQAdmin.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/joram/ActiveMQAdmin.java?rev=1495057&r1=1495056&r2=1495057&view=diff
==============================================================================
--- activemq/trunk/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/joram/ActiveMQAdmin.java
(original)
+++ activemq/trunk/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/joram/ActiveMQAdmin.java
Thu Jun 20 15:43:44 2013
@@ -56,29 +56,33 @@ public class ActiveMQAdmin implements Ad
         }
     }
 
-    static public void enableJMSFrameTracing() throws FileNotFoundException {
-        final SimpleFormatter formatter = new SimpleFormatter();
-        String outputStreamName = System.getProperty("java.io.tmpdir") + "/amqp-trace.txt";
-        final PrintStream out = new PrintStream(new FileOutputStream(new File(outputStreamName)));
-        Handler handler = new Handler() {
-            @Override
-            public void publish(LogRecord r) {
-                out.println(String.format("%s:%s", r.getLoggerName(), r.getMessage()));
-            }
-
-            @Override
-            public void flush() {
-                out.flush();
-            }
-
-            @Override
-            public void close() throws SecurityException {
-            }
-        };
-
-        Logger log = Logger.getLogger("FRM");
-        log.addHandler(handler);
-        log.setLevel(Level.FINEST);
+    static public void enableJMSFrameTracing() {
+        try {
+            final SimpleFormatter formatter = new SimpleFormatter();
+            String outputStreamName = "amqp-trace.txt";
+            final PrintStream out = new PrintStream(new FileOutputStream(new File(outputStreamName)));
+            Handler handler = new Handler() {
+                @Override
+                public void publish(LogRecord r) {
+                    out.println(String.format("%s:%s", r.getLoggerName(), r.getMessage()));
+                }
+
+                @Override
+                public void flush() {
+                    out.flush();
+                }
+
+                @Override
+                public void close() throws SecurityException {
+                }
+            };
+
+            Logger log = Logger.getLogger("FRM");
+            log.addHandler(handler);
+            log.setLevel(Level.FINEST);
+        } catch (FileNotFoundException e) {
+            throw new RuntimeException(e);
+        }
     }
 
     protected BrokerService createBroker() throws Exception {

Modified: activemq/trunk/activemq-amqp/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-amqp/src/test/resources/log4j.properties?rev=1495057&r1=1495056&r2=1495057&view=diff
==============================================================================
--- activemq/trunk/activemq-amqp/src/test/resources/log4j.properties (original)
+++ activemq/trunk/activemq-amqp/src/test/resources/log4j.properties Thu Jun 20 15:43:44 2013
@@ -20,7 +20,8 @@
 #
 log4j.rootLogger=WARN, console, file
 log4j.logger.org.apache.activemq=INFO
-log4j.logger.org.apache.activemq.transport.amqp=TRACE
+log4j.logger.org.apache.activemq.transport.amqp=INFO
+log4j.logger.org.apache.activemq.transport.amqp.FRAMES=TRACE
 log4j.logger.org.fusesource=INFO
 
 # Console will only display warnnings



Mime
View raw message