MDC logging
Skip to end of metadata
Go to start of metadata

MDC logging

Available as of Camel 2.7

In Camel 2.7 we migrated to use slf4j as the logging framework in Camel. This allows us to support MDC logging.
See more details about MDC logging in the logback manual.

The log kit in use must support MDC, such as:

See the log kit documentation how to configure and use MDC.

Enabling in Camel

To enable MDC logging in Camel you can do it as follows:

In XML you enable it using the useMDCLogging attribute as follows:

MDC information

Camel provides the following context information available for MDC:

Camel 2.9.x or older

Key

Description

exchangeId

The exchange id

messageId

Camel 2.9.1: The message 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

breadcrumbId

Camel 2.8: An unique id used for tracking messages across transports.

camelContextId

Camel 2.8.3/2.9: the camel context id used for tracking the message from different camel context.

Camel 2.10 onwards

Key

Description

camel.exchangeId

The exchange id

camel.messageId

The message id

camel.correlationId

The correlation id of the exchange if it's correlated. For example a sub message from the Splitter EIP

camel.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.

camel.routeId

The id of the route, in which the exchange is currently being routed

camel.breadcrumbId

An unique id used for tracking messages across transports.

camel.contextId

The camel context id used for tracking the message from different camel context.

The keys are subject to change as we want to align and leverage MDC across other Apache products such as ActiveMQ, ServiceMix and Karaf.

Example using log4j

If you use log4j you can configure MDC in the log4j.properties file as shown:

Camel will log on startup if MDC is enabled or not

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:

Using breadcrumb

Available as of Camel 2.8
The breadcrumbId key for MDC logging is only available if useBreadcrumb option has been enabled on CamelContext (its default enabled). When enabled Camel will enrich the Camel Message by adding a header to it with the key breadcrumbId containing the id. Camel will use the messageId if no existing breadcrumbId was found in the message. By storing the breadcrumb as a header allow us to transport the breadcrumb across transports which supports message body and headers. For example HTTP and JMS and many other transports does that.

If you want to disable breadcrumb you do as follows in Java

And in XML DSL

Labels
  • No labels