THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
Wiki Markup |
---|
h2. MDC logging *Available as of Camel 2.7* In Camel 2.7 we migrated to use [slf4j|http://www.slf4j.org/] as the logging framework in Camel. This allows us to support [MDC logging|http://www.slf4j.org/api/org/slf4j/MDC.html]. See more details about MDC logging in the [logback manual|http://logback.qos.ch/manual/mdc.html]. The log kit in use must support MDC, such as: - [log4j|http://logging.apache.org/log4j/1.2/] - [logback|http://logback.qos.ch/] - [pax logging|http://wiki.ops4j.org/display/paxlogging/Pax+Logging] See the log kit documentation how to configure and use MDC. h3. Enabling in Camel To enable MDC logging in Camel you can do it as follows: {code} CamelContext context = ... context.setUseMDCLogging(true); ... {code} In XML you enable it using the {{useMDCLogging}} attribute as follows: {code:xml} <camelContext xmlns="http://camel.apache.org/schema/spring" useMDCLogging="true"> ... </camelContext> {code} h3. MDC information Camel provides the following context information available for MDC: {div:class=confluenceTableSmall} || Key || Description || | {{exchangeId}} | The exchange id | | {{correlationId}} | The correlation id of the exchange if it's correlated. For example a sub message from the [Splitter] EIP | | {{transactionKey}} | The id of the transaction for transacted exchanges. Note the id is not unique, but its the id of the transaction template that marks the transaction boundary for the given transaction. Hence we decided to name the key {{transactionKey}} and not {{transactionID}} to point out this fact. | | {{routeId}} | The id of the route, in which the exchange is currently being routed | {div} The keys are subject to change as we want to align and leverage MDC across other Apache products such as [ActiveMQ|http://activemq.apache.org], [ServiceMix|http://servicemix.apache.org/] and [Karaf|http://karaf.apache.org/]. h3. Example using log4j If you use log4j you can configure MDC in the log4j.properties file as shown: {code} log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{exchangeId} - %-10.10X{correlationId} - %-10.10X{routeId} - %m%n {code} Camel will log on startup if MDC is enabled or not {code} INFO SpringCamelContext - - - - MDC logging is enabled on CamelContext: camel-1 {code} The follow snippet is from an unit test which shows MDC in use. Notice the exchange id and route id is displayed in their respective columns in the log file: {code} INFO SpringCamelContext - - - - Apache Camel (CamelContext: camel-1) started in 1.228 seconds INFO foo - 358739-0-2 - - route-a - Exchange[ExchangePattern:InOnly, BodyType:String, Body:Hello World] INFO bar - 358739-0-2 - - route-b - Exchange[ExchangePattern:InOnly, BodyType:String, Body:Hello World] INFO MockEndpoint - - - - Asserting: Endpoint[mock://result] is satisfied {code} |