Protect against appending recursion (In case your JMS provider appends to log4j in the process of sending a JMS message).

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1407200 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2012-11-08 18:13:20 +00:00
parent ecaae53fe8
commit 763aa74757
1 changed files with 13 additions and 6 deletions

View File

@ -137,13 +137,20 @@ public abstract class JmsLogAppenderSupport extends AppenderSkeleton {
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();
}
}
}