How can I log the processing of a Message?
Camel provides many ways to log the fact that you are processing a message. Here are just a few examples:
Using log DSL
In Camel 2.2 you can use the
Which will construct a String message at runtime using the Simple language. The log message will by logged at
Difference between log in the DSL and [Log] component
Using Logger instance from the the Registry
As of Camel 2.12.4/2.13.1, if no logger name or logger instance is passed to log DSL, there is a Registry lookup performed to find single instance of
Logging message body with streamed messages
The log DSL have overloaded methods to set the logging level and/or name as well.
and to set a logger name
Since Camel 2.12.4/2.13.1 the logger instance may be used as well:
For example you can use this to log the file name being processed if you consume files.
Using log DSL from Spring
In Spring DSL it is also easy to use log DSL as shown below:
The log tag has attributes to set the
Since Camel 2.12.4/2.13.1 it is possible to reference logger instance. For example:
Configuring log name globally
Available as of Camel 2.17
By default the log name is the route id. If you want to use a different log name, you would need to configure the logName option. However if you have many logs and you want all of them to use the same log name, then you would need to set that logName option on all of them.
With Camel 2.17 onwards you can configure a global log name that is used instead of the route id, eg
And in XML
Using slf4j Marker
Available as of Camel 2.9
You can specify a marker name in the DSL
Using log DSL in OSGi
Improvement as of Camel 2.12.4/2.13.1
When using log DSL inside OSGi (e.g., in Karaf), the underlying logging mechanisms are provided by PAX logging. It searches for a bundle which invokes
In some scenarios it is required that the bundle associated with logger should be the bundle which contains route definition. This is possible using provided logger instance both for Java DSL and Spring DSL (see the examples above).
Using This Pattern
If you would like to use this EIP Pattern then please read the Getting Started, you may also find the Architecture useful particularly the description of Endpoint and URIs. Then you could try out some of the Examples first before trying this pattern out.