Red Hat Training

A Red Hat training course is available for Red Hat Fuse

11.2. LogEIP


Apache Camel provides several ways to perform logging in a route:
  • Using the log DSL command.
  • Using the Log component, which can log the message content.
  • Using the Tracer, which traces message flow.
  • Using a Processor or a Bean endpoint to perform logging in Java.
Difference between the log DSL command and the log component
The log DSL is much lighter and meant for logging human logs such as Starting to do .... It can only log a message based on the Simple language. In contrast, the Log component is a fully featured logging component. The Log component is capable of logging the message itself and you have many URI options to control the logging.

Java DSL example

Since Apache Camel 2.2, you can use the log DSL command to construct a log message at run time using the Simple expression language. For example, you can create a log message within a route, as follows:
from("direct:start").log("Processing ${id}").to("bean:foo");
This route constructs a String format message at run time. The log message will by logged at INFO level, using the route ID as the log name. By default, routes are named consecutively, route-1, route-2 and so on. But you can use the DSL command, routeId("myCoolRoute"), to specify a custom route ID.
The log DSL also provides variants that enable you to set the logging level and the log name explicitly. For example, to set the logging level explicitly to LoggingLevel.DEBUG, you can invoke the log DSL as follows:
has overloaded methods to set the logging level and/or name as well.
from("direct:start").log(LoggingLevel.DEBUG, "Processing ${id}").to("bean:foo");
To set the log name to fileRoute, you can invoke the log DSL as follows:
from("file://target/files").log(LoggingLevel.DEBUG, "fileRoute", "Processing file ${file:name}").to("bean:foo");

XML DSL example

In XML DSL, the log DSL is represented by the log element and the log message is specified by setting the message attribute to a Simple expression, as follows:
<route id="foo">
    <from uri="direct:foo"/>
    <log message="Got ${body}"/>
    <to uri="mock:foo"/>
The log element supports the message, loggingLevel and logName attributes. For example:
<route id="baz">
    <from uri="direct:baz"/>
    <log message="Me Got ${body}" loggingLevel="FATAL" logName="cool"/>
    <to uri="mock:baz"/>

Global Log Name

The route ID is used as the the default log name. Since Apache Camel 2.17 the log name can be changed by configuring a logname parameter.
Java DSL, configure the log name based on the following example:
CamelContext context = ...
context.getProperties().put(Exchange.LOG_EIP_NAME, "");
In XML, configure the log name in the following way:
<camelContext ...>
    <property key="CamelLogEipName" value=""/>
If you have more than one log and you want to have the same log name on all of them, you must add the configuration to each log.