activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject [3/5] git commit: https://issues.apache.org/jira/browse/AMQ-3779 - add perDestinationLogger attribute - logger for producer send of the form: org.apache.activemq.broker.util.LoggingBrokerPlugin.<type>.<name>
Date Mon, 02 Sep 2013 23:40:06 GMT
https://issues.apache.org/jira/browse/AMQ-3779 - add perDestinationLogger attribute - logger
for producer send of the form: org.apache.activemq.broker.util.LoggingBrokerPlugin.<type>.<name>


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/3222767e
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/3222767e
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/3222767e

Branch: refs/heads/trunk
Commit: 3222767e796a23ed96478e68858774cb45740bfc
Parents: 0525f88
Author: gtully <gtully@apache.org>
Authored: Tue Sep 3 00:32:22 2013 +0100
Committer: gtully <gtully@apache.org>
Committed: Tue Sep 3 00:32:22 2013 +0100

----------------------------------------------------------------------
 .../broker/util/LoggingBrokerPlugin.java        | 21 +++++-
 .../org/apache/activemq/bugs/AMQ3779Test.java   | 76 ++++++++++++++++++++
 2 files changed, 96 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/3222767e/activemq-broker/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
----------------------------------------------------------------------
diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
b/activemq-broker/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
index a4184e3..ea527c1 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/broker/util/LoggingBrokerPlugin.java
@@ -50,6 +50,7 @@ public class LoggingBrokerPlugin extends BrokerPluginSupport {
     private boolean logConsumerEvents = false;
     private boolean logProducerEvents = false;
     private boolean logInternalEvents = false;
+    private boolean perDestinationLogger = false;
 
     /**
      * JSR-250 callback wrapper; converts checked exceptions to runtime exceptions
@@ -282,11 +283,21 @@ public class LoggingBrokerPlugin extends BrokerPluginSupport {
     @Override
     public void send(ProducerBrokerExchange producerExchange, Message messageSend) throws
Exception {
         if (isLogAll() || isLogProducerEvents()) {
-            LOG.info("Sending message : " + messageSend.copy());
+            logSend(messageSend.copy());
         }
         super.send(producerExchange, messageSend);
     }
 
+    private void logSend(Message copy) {
+        Logger perDestinationsLogger = LOG;
+        if (isPerDestinationLogger()) {
+            ActiveMQDestination destination = copy.getDestination();
+            perDestinationsLogger = LoggerFactory.getLogger(LOG.getName() +
+                    "." + destination.getDestinationTypeAsString() + "." + destination.getPhysicalName());
+        }
+        perDestinationsLogger.info("Sending message : " + copy);
+    }
+
     @Override
     public void beginTransaction(ConnectionContext context, TransactionId xid) throws Exception
{
         if (isLogAll() || isLogTransactionEvents()) {
@@ -606,4 +617,12 @@ public class LoggingBrokerPlugin extends BrokerPluginSupport {
         buf.append(")");
         return buf.toString();
     }
+
+    public void setPerDestinationLogger(boolean perDestinationLogger) {
+        this.perDestinationLogger = perDestinationLogger;
+    }
+
+    public boolean isPerDestinationLogger() {
+        return perDestinationLogger;
+    }
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/3222767e/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3779Test.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3779Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3779Test.java
new file mode 100644
index 0000000..5a410e8
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3779Test.java
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.bugs;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.AutoFailTestSupport;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.util.LoggingBrokerPlugin;
+import org.apache.activemq.util.DefaultTestAppender;
+import org.apache.log4j.Appender;
+import org.apache.log4j.Logger;
+import org.apache.log4j.spi.LoggingEvent;
+
+public class AMQ3779Test extends AutoFailTestSupport {
+
+    private static final Logger logger = Logger.getLogger(AMQ3779Test.class);
+    private static final String qName = "QNameToFind";
+
+    public void testLogPerDest() throws Exception {
+
+        final AtomicBoolean ok = new AtomicBoolean(false);
+        Appender appender = new DefaultTestAppender() {
+            @Override
+            public void doAppend(LoggingEvent event) {
+                if (event.getLoggerName().toString().contains(qName)) {
+                    ok.set(true);
+                }
+            }
+        };
+        logger.getRootLogger().addAppender(appender);
+
+        try {
+
+            BrokerService broker = new BrokerService();
+            LoggingBrokerPlugin loggingBrokerPlugin = new LoggingBrokerPlugin();
+            loggingBrokerPlugin.setPerDestinationLogger(true);
+            loggingBrokerPlugin.setLogAll(true);
+            broker.setPlugins(new LoggingBrokerPlugin[]{loggingBrokerPlugin});
+            broker.start();
+
+
+            Connection connection = new ActiveMQConnectionFactory(broker.getVmConnectorURI()).createConnection();
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageProducer messageProducer = session.createProducer(session.createQueue(qName));
+            messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT);
+            connection.start();
+
+            messageProducer.send(session.createTextMessage("Hi"));
+            connection.close();
+
+            assertTrue("got expected log message", ok.get());
+        } finally {
+            logger.removeAppender(appender);
+        }
+    }
+}


Mime
View raw message