activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1407200 - /activemq/trunk/activemq-log4j-appender/src/main/java/org/apache/activemq/util/JmsLogAppenderSupport.java
Date Thu, 08 Nov 2012 18:13:20 GMT
Author: chirino
Date: Thu Nov  8 18:13:20 2012
New Revision: 1407200

URL: http://svn.apache.org/viewvc?rev=1407200&view=rev
Log:
Protect against appending recursion (In case your JMS provider appends to log4j in the process
of sending a JMS message).

Modified:
    activemq/trunk/activemq-log4j-appender/src/main/java/org/apache/activemq/util/JmsLogAppenderSupport.java

Modified: activemq/trunk/activemq-log4j-appender/src/main/java/org/apache/activemq/util/JmsLogAppenderSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-log4j-appender/src/main/java/org/apache/activemq/util/JmsLogAppenderSupport.java?rev=1407200&r1=1407199&r2=1407200&view=diff
==============================================================================
--- activemq/trunk/activemq-log4j-appender/src/main/java/org/apache/activemq/util/JmsLogAppenderSupport.java
(original)
+++ activemq/trunk/activemq-log4j-appender/src/main/java/org/apache/activemq/util/JmsLogAppenderSupport.java
Thu Nov  8 18:13:20 2012
@@ -137,13 +137,20 @@ public abstract class JmsLogAppenderSupp
         return getSession().createProducer(null);
     }
 
+    private static final ThreadLocal<Object> APPENDING = new ThreadLocal<Object>();
+
     protected void append(LoggingEvent event) {
-        try {
-            Message message = createMessage(event);
-            Destination destination = getDestination(event);
-            getProducer().send(destination, message);
-        } catch (Exception e) {
-            getErrorHandler().error("Could not send message due to: " + e, e, JMS_PUBLISH_ERROR_CODE,
event);
+        if( APPENDING.get()==null ) {
+            APPENDING.set(true);
+            try {
+                Message message = createMessage(event);
+                Destination destination = getDestination(event);
+                getProducer().send(destination, message);
+            } catch (Exception e) {
+                getErrorHandler().error("Could not send message due to: " + e, e, JMS_PUBLISH_ERROR_CODE,
event);
+            } finally {
+                APPENDING.remove();
+            }
         }
     }
 



Mime
View raw message