You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Log

How can I log processing a Message?

Camel provides many ways to log processing a message. Here is just some examples.

You can use the Log component which logs the Message content.
Or you can use the Tracer which trace logs message flow.

You can also use a Processor or Bean and log from Java code.

Using log DSL

And in Camel 2.2 you can use the log DSL which allows you to use an Expression to construct a dynamic message which gets logged.
For example you can do

from("direct:start").log("Processing ${id}").to("bean:foo");

Which will construct a String message at runtime using the Simple language. The log message will by logged at INFO level using the route id as the log name. By default a route is named route-1, route-2 etc. But you can use the routeId("myCoolRoute") to set a route name of choice.

The log DSL have overloaded methods to set the logging level and/or name as well.

from("direct:start").log(LoggingLevel.DEBUG, "Processing ${id}").to("bean:foo");

For example you can use this to log the file name being processed if you consume files.

from("file://target/files").log(LoggingLevel.DEBUG, "Processing file ${file:name}").to("bean:foo");

Using log DSL from Spring

In Spring DSL its also easy to use log DSL as shown below:

        <route id="foo">
            <from uri="direct:foo"/>
            <log message="Got ${body}"/>
            <to uri="mock:foo"/>
        </route>

The log tag has attributes to set the message, loggingLevel and logName. For example:

        <route id="baz">
            <from uri="direct:baz"/>
            <log message="Me Got ${body}" loggingLevel="FATAL" logName="cool"/>
            <to uri="mock:baz"/>
        </route>

See Also

TODO:

  • No labels