Log ComponentThe log: component logs message exchanges to the underlying logging mechanism. Camel 2.7 or better uses sfl4j which allows you to configure logging via, among others: Camel 2.6 or lower uses commons-logging which allows you to configure logging via, among others:
Refer to the commons-logging user guide for a more complete overview of how to use and configure commons-logging. URI formatlog:loggingCategory[?options] Where loggingCategory is the name of the logging category to use. You can append query options to the URI in the following format, ?option=value&option=value&... For example, a log endpoint typically specifies the logging level using the level option, as follows: log:org.apache.camel.example?level=DEBUG The default logger logs every exchange (regular logging). But Camel also ships with the Throughput logger, which is used whenever the groupSize option is specified.
Options
note: groupDelay and groupActiveOnly are only applicable when using groupInterval FormattingThe log formats the execution of exchanges to log lines.
Regular logger sampleIn the route below we log the incoming orders at DEBUG level before the order is processed: from("activemq:orders").to("log:com.mycompany.order?level=DEBUG").to("bean:processOrder"); Or using Spring XML to define the route: <route> <from uri="activemq:orders"/> <to uri="log:com.mycompany.order?level=DEBUG"/> <to uri="bean:processOrder"/> </route> Regular logger with formatter sampleIn the route below we log the incoming orders at INFO level before the order is processed. from("activemq:orders"). to("log:com.mycompany.order?showAll=true&multiline=true").to("bean:processOrder"); Throughput logger with groupSize sampleIn the route below we log the throughput of the incoming orders at DEBUG level grouped by 10 messages. from("activemq:orders"). to("log:com.mycompany.order?level=DEBUG&groupSize=10").to("bean:processOrder"); Throughput logger with groupInterval sampleThis route will result in message stats logged every 10s, with an initial 60s delay and stats should be displayed even if there isn't any message traffic. from("activemq:orders"). to("log:com.mycompany.order?level=DEBUG&groupInterval=10000&groupDelay=60000&groupActiveOnly=false").to("bean:processOrder"); The following will be logged:
"Received: 1000 new messages, with total 2000 so far. Last group took: 10000 millis which is: 100 messages per second. average: 100"
Full customization of the logging outputAvailable as of Camel 2.11 With the options outlined in the Formatting section, you can control much of the output of the logger. However, log lines will always follow this structure:
Exchange[Id:ID-machine-local-50656-1234567901234-1-2, ExchangePattern:InOut,
Properties:{CamelToEndpoint=log://org.apache.camel.component.log.TEST?showAll=true,
CamelCreatedTimestamp=Thu Mar 28 00:00:00 WET 2013},
Headers:{breadcrumbId=ID-machine-local-50656-1234567901234-1-1}, BodyType:String, Body:Hello World, Out: null]
This format is unsuitable in some cases, perhaps because you need to...
Whenever you require absolute customization, you can create a class that implements the ExchangeFormatter interface. Within the format(Exchange) method you have access to the full Exchange, so you can select and extract the precise information you need, format it in a custom manner and return it. The return value will become the final log message. You can have the Log component pick up your custom ExchangeFormatter in either of two ways: Explicitly instantiating the LogComponent in your Registry: <bean name="log" class="org.apache.camel.component.log.LogComponent"> <property name="exchangeFormatter" ref="myCustomFormatter" /> </bean> Convention over configuration: Simply by registering a bean with the name logFormatter; the Log Component is intelligent enough to pick it up automatically. <bean name="logFormatter" class="com.xyz.MyCustomExchangeFormatter" /> NOTE: the ExchangeFormatter gets applied to all Log endpoints within that Camel Context. If you need different ExchangeFormatters for different endpoints, just instantiate the LogComponent as many times as needed, and use the relevant bean name as the endpoint prefix. See Also
|