camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1240063 - in /camel/trunk/components: camel-jms/src/test/resources/ camel-jms/src/test/resources/org/apache/camel/component/jms/tx/ camel-spring/src/main/java/org/apache/camel/spring/spi/
Date Fri, 03 Feb 2012 10:30:08 GMT
Author: davsclaus
Date: Fri Feb  3 10:30:08 2012
New Revision: 1240063

URL: http://svn.apache.org/viewvc?rev=1240063&view=rev
Log:
CAMEL-4961: Improved TX commit/rollback logging a bit

Modified:
    camel/trunk/components/camel-jms/src/test/resources/log4j.properties
    camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java

Modified: camel/trunk/components/camel-jms/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/log4j.properties?rev=1240063&r1=1240062&r2=1240063&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/log4j.properties (original)
+++ camel/trunk/components/camel-jms/src/test/resources/log4j.properties Fri Feb  3 10:30:08
2012
@@ -18,7 +18,7 @@
 #
 # The logging properties used
 #
-log4j.rootLogger=INFO, out
+log4j.rootLogger=INFO, stdout
 
 #log4j.logger.org.apache.activemq.spring=WARN
 #log4j.logger.org.apache.camel.component.jms=TRACE
@@ -27,6 +27,7 @@ log4j.rootLogger=INFO, out
 #log4j.logger.org.apache.camel=DEBUG
 #log4j.logger.org.springframework.jms.listener=TRACE
 #log4j.logger.org.apache.camel.management=DEBUG
+#log4j.logger.org.apache.camel.spring.spi=DEBUG
 
 # CONSOLE appender not used by default
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender

Modified: camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml?rev=1240063&r1=1240062&r2=1240063&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
(original)
+++ camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/JMSTransactionIsTransactedRedeliveredTest.xml
Fri Feb  3 10:30:08 2012
@@ -54,8 +54,9 @@
       <!-- enable JMX -->
       <jmxAgent id="agent" disabled="false"/>
 
-      <!-- we do not want any exceptions to be logged, neither that a rollback occurred
-->
-      <errorHandler id="txEH" type="TransactionErrorHandler" rollbackLoggingLevel="OFF">
+      <!-- we want TX rollbacks to be logged at WARN level -->
+      <errorHandler id="txEH" type="TransactionErrorHandler" rollbackLoggingLevel="WARN">
+        <!-- we do not want any exceptions to be logged with stacktraces -->
         <redeliveryPolicy logStackTrace="false" logExhausted="false"/>
       </errorHandler>
 

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java?rev=1240063&r1=1240062&r2=1240063&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
(original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/spi/TransactionErrorHandler.java
Fri Feb  3 10:30:08 2012
@@ -126,23 +126,17 @@ public class TransactionErrorHandler ext
             // mark the beginning of this transaction boundary
             exchange.getUnitOfWork().beginTransactedBy(transactionKey);
 
-            if (log.isDebugEnabled()) {
-                log.debug("Transaction begin ({}) redelivered({}) for {})", new Object[]{transactionKey,
redelivered, ids});
-            }
-
+            // do in transaction
+            logTransactionBegin(redelivered, ids);
             doInTransactionTemplate(exchange);
+            logTransactionCommit(redelivered, ids);
 
-            if (log.isDebugEnabled()) {
-                log.debug("Transaction commit ({}) redelivered({}) for {})", new Object[]{transactionKey,
redelivered, ids});
-            }
         } catch (TransactionRollbackException e) {
-            // ignore as its just a dummy exception to force spring TX to rollback
-            if (log.isDebugEnabled()) {
-                log.debug("Transaction rollback ({}) redelivered({}) for {} due exchange
was marked for rollbackOnly", new Object[]{transactionKey, redelivered, ids});
-            }
+            // do not set as exception, as its just a dummy exception to force spring TX
to rollback
+            logTransactionRollback(redelivered, ids, null, true);
         } catch (Throwable e) {
             exchange.setException(e);
-            logTransactionRollback(redelivered, ids, e);
+            logTransactionRollback(redelivered, ids, e, false);
         } finally {
             // mark the end of this transaction boundary
             exchange.getUnitOfWork().endTransactedBy(transactionKey);
@@ -229,21 +223,68 @@ public class TransactionErrorHandler ext
     }
 
     /**
-     * Logs the transaction rollback
+     * Logs the transaction begin
+     */
+    private void logTransactionBegin(String redelivered, String ids) {
+        if (log.isDebugEnabled()) {
+            log.debug("Transaction begin ({}) redelivered({}) for {})", new Object[]{transactionKey,
redelivered, ids});
+        }
+    }
+
+    /**
+     * Logs the transaction commit
      */
-    private void logTransactionRollback(String redelivered, String ids, Throwable e) {
+    private void logTransactionCommit(String redelivered, String ids) {
+        if ("true".equals(redelivered)) {
+            // okay its a redelivered message so log at INFO level if rollbackLoggingLevel
is INFO or higher
+            // this allows people to know that the redelivered message was committed this
time
+            if (rollbackLoggingLevel == LoggingLevel.INFO || rollbackLoggingLevel == LoggingLevel.WARN
|| rollbackLoggingLevel == LoggingLevel.ERROR) {
+                log.info("Transaction commit ({}) redelivered({}) for {})", new Object[]{transactionKey,
redelivered, ids});
+                // return after we have logged
+                return;
+            }
+        }
+
+        // log non redelivered by default at DEBUG level
+        log.debug("Transaction commit ({}) redelivered({}) for {})", new Object[]{transactionKey,
redelivered, ids});
+    }
+
+    /**
+     * Logs the transaction rollback.
+     */
+    private void logTransactionRollback(String redelivered, String ids, Throwable e, boolean
rollbackOnly) {
         if (rollbackLoggingLevel == LoggingLevel.OFF) {
             return;
         } else if (rollbackLoggingLevel == LoggingLevel.ERROR && log.isErrorEnabled())
{
-            log.error("Transaction rollback ({}) redelivered({}) for {} caught: {}", new
Object[]{transactionKey, redelivered, ids, e.getMessage()});
+            if (rollbackOnly) {
+                log.error("Transaction rollback ({}) redelivered({}) for {} due exchange
was marked for rollbackOnly", new Object[]{transactionKey, redelivered, ids});
+            } else {
+                log.error("Transaction rollback ({}) redelivered({}) for {} caught: {}",
new Object[]{transactionKey, redelivered, ids, e.getMessage()});
+            }
         } else if (rollbackLoggingLevel == LoggingLevel.WARN && log.isWarnEnabled())
{
-            log.warn("Transaction rollback ({}) redelivered({}) for {} caught: {}", new Object[]{transactionKey,
redelivered, ids, e.getMessage()});
+            if (rollbackOnly) {
+                log.warn("Transaction rollback ({}) redelivered({}) for {} due exchange was
marked for rollbackOnly", new Object[]{transactionKey, redelivered, ids});
+            } else {
+                log.warn("Transaction rollback ({}) redelivered({}) for {} caught: {}", new
Object[]{transactionKey, redelivered, ids, e.getMessage()});
+            }
         } else if (rollbackLoggingLevel == LoggingLevel.INFO && log.isInfoEnabled())
{
-            log.info("Transaction rollback ({}) redelivered({}) for {} caught: {}", new Object[]{transactionKey,
redelivered, ids, e.getMessage()});
+            if (rollbackOnly) {
+                log.info("Transaction rollback ({}) redelivered({}) for {} due exchange was
marked for rollbackOnly", new Object[]{transactionKey, redelivered, ids});
+            } else {
+                log.info("Transaction rollback ({}) redelivered({}) for {} caught: {}", new
Object[]{transactionKey, redelivered, ids, e.getMessage()});
+            }
         } else if (rollbackLoggingLevel == LoggingLevel.DEBUG && log.isDebugEnabled())
{
-            log.debug("Transaction rollback ({}) redelivered({}) for {} caught: {}", new
Object[]{transactionKey, redelivered, ids, e.getMessage()});
+            if (rollbackOnly) {
+                log.debug("Transaction rollback ({}) redelivered({}) for {} due exchange
was marked for rollbackOnly", new Object[]{transactionKey, redelivered, ids});
+            } else {
+                log.debug("Transaction rollback ({}) redelivered({}) for {} caught: {}",
new Object[]{transactionKey, redelivered, ids, e.getMessage()});
+            }
         } else if (rollbackLoggingLevel == LoggingLevel.TRACE && log.isTraceEnabled())
{
-            log.trace("Transaction rollback ({}) redelivered({}) for {} caught: {}", new
Object[]{transactionKey, redelivered, ids, e.getMessage()});
+            if (rollbackOnly) {
+                log.trace("Transaction rollback ({}) redelivered({}) for {} due exchange
was marked for rollbackOnly", new Object[]{transactionKey, redelivered, ids});
+            } else {
+                log.trace("Transaction rollback ({}) redelivered({}) for {} caught: {}",
new Object[]{transactionKey, redelivered, ids, e.getMessage()});
+            }
         }
     }
 



Mime
View raw message