Camel includes a Log Component that is useful for debug logging in that it makes it easy to log most, or all of the contents of the messages flowing through your routes. Typically this component is only used temporarily within your routes to help you debug, and is expected to be removed before deployment. The Enabling step-by-step tracing in code recipe will cover how you can enable a similar level of logging at runtime. To log significant events within your routes, see the Log EIP (the Logging meaningful steps within your route recipe).
This recipe will show you how to use the Log Component to help debug your integrations.
The Java code for this recipe is located in the org.camelcookbook.monitoring.log
package. The Spring XML files are located under src/main/resources/META-INF/spring
and prefixed with log
.
The format for the Log Component URI is as follows:
log:<log name>[?<query options>]
In the XML DSL, this is written as:
<route>
<from uri="direct:start"/>
<to uri="log:myLog"/>
<to uri="mock:result"/>
</route>
In the Java DSL, the same route is expressed as:
from("direct:start")
.to("log:myLog")
.to("mock:result");
The resulting log should look something like the following, assuming a message with the body of "Hello Camel" is passed in:
INFO myLog - Exchange[ExchangePattern:InOnly, BodyType:String, Body:Hello Camel]
The Log Component, by default, will log at the INFO
logging level, and output the following information to the log system: the MEP (Message Exchange Pattern), the message body data type, and the contents of the message body.
There are a number of formatting options within the Log Component that allow you to output more information. For example, to show the full contents of the message, and nicely format it on multiple log lines (versus one very long line), you could configure the endpoint as follows in the XML DSL:
<route>
<from uri="direct:start"/>
<to uri="log:myLog?showAll=true&multiline=true"/>
<to uri="mock:result"/>
</route>
In the Java DSL, the same configuration is applied as follows:
from("direct:start")
.to("log:myLog?showAll=true&multiline=true")
.to("mock:result");
Here is a sample of the type of output you would see from the preceding configuration. Notice how the log entry is broken up across multiple lines by category (properties, headers, body, and so on):
INFO myLog - Exchange[ , Id:ID-grelber-local-65355-1374412338126-1-2 , ExchangePattern:InOnly , Properties:{CamelToEndpoint=log://myLog?multiline=true&showAll=true, CamelCreatedTimestamp=Sun Jul 21 09:12:18EDT 2013} , Headers:{breadcrumbId=ID-grelber-local-65355-1374412338126-1-1} , BodyType:String , Body:Hello Camel , Out: null ]
3.149.213.44