You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2011/10/19 05:09:42 UTC
svn commit: r1185952 -
/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
Author: ningjiang
Date: Wed Oct 19 03:09:42 2011
New Revision: 1185952
URL: http://svn.apache.org/viewvc?rev=1185952&view=rev
Log:
CAMEL-4547 Add camelContextId to the mdc logging keys
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java?rev=1185952&r1=1185951&r2=1185952&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MDCUnitOfWork.java Wed Oct 19 03:09:42 2011
@@ -36,6 +36,7 @@ public class MDCUnitOfWork extends Defau
public static final String MDC_EXCHANGE_ID = "exchangeId";
public static final String MDC_CORRELATION_ID = "correlationId";
public static final String MDC_ROUTE_ID = "routeId";
+ public static final String MDC_CAMEL_CONTEXT_ID = "camelContextId";
public static final String MDC_TRANSACTION_KEY = "transactionKey";
private static final Logger LOG = LoggerFactory.getLogger(MDCUnitOfWork.class);
@@ -44,6 +45,7 @@ public class MDCUnitOfWork extends Defau
private final String originalExchangeId;
private final String originalCorrelationId;
private final String originalRouteId;
+ private final String originalCamelContextId;
private final String originalTransactionKey;
public MDCUnitOfWork(Exchange exchange) {
@@ -54,10 +56,13 @@ public class MDCUnitOfWork extends Defau
this.originalBreadcrumbId = MDC.get(MDC_BREADCRUMB_ID);
this.originalCorrelationId = MDC.get(MDC_CORRELATION_ID);
this.originalRouteId = MDC.get(MDC_ROUTE_ID);
+ this.originalCamelContextId = MDC.get(MDC_CAMEL_CONTEXT_ID);
this.originalTransactionKey = MDC.get(MDC_TRANSACTION_KEY);
// must add exchange id in constructor
MDC.put(MDC_EXCHANGE_ID, exchange.getExchangeId());
+ // the camel context id is from exchange
+ MDC.put(MDC_CAMEL_CONTEXT_ID, exchange.getContext().getName());
// and add optional correlation id
String corrId = exchange.getProperty(Exchange.CORRELATION_ID, String.class);
if (corrId != null) {
@@ -145,6 +150,11 @@ public class MDCUnitOfWork extends Defau
} else {
MDC.remove(MDC_ROUTE_ID);
}
+ if (this.originalCamelContextId != null) {
+ MDC.put(MDC_CAMEL_CONTEXT_ID, originalCamelContextId);
+ } else {
+ MDC.remove(MDC_CAMEL_CONTEXT_ID);
+ }
if (this.originalTransactionKey != null) {
MDC.put(MDC_TRANSACTION_KEY, originalTransactionKey);
} else {
@@ -168,12 +178,14 @@ public class MDCUnitOfWork extends Defau
private final String exchangeId;
private final String correlationId;
private final String routeId;
+ private final String camelContextId;
private MDCCallback(AsyncCallback delegate) {
this.delegate = delegate;
this.exchangeId = MDC.get(MDC_EXCHANGE_ID);
this.breadcrumbId = MDC.get(MDC_BREADCRUMB_ID);
this.correlationId = MDC.get(MDC_CORRELATION_ID);
+ this.camelContextId = MDC.get(MDC_CAMEL_CONTEXT_ID);
String routeId = MDC.get(MDC_ROUTE_ID);
if (routeId != null) {
@@ -200,6 +212,9 @@ public class MDCUnitOfWork extends Defau
if (routeId != null) {
MDC.put(MDC_ROUTE_ID, routeId);
}
+ if (camelContextId != null) {
+ MDC.put(MDC_CAMEL_CONTEXT_ID, camelContextId);
+ }
}
} finally {
// muse ensure delegate is invoked