...
The log: component logs message exchanges to the underlying logging mechanism.
Include Page | ||||
---|---|---|---|---|
|
URI format
Code Block |
---|
log:loggingCategory[?options]
|
...
For example, a log endpoint typically specifies the logging level using the level
option, as follows:
Code Block |
---|
log:org.apache.camel.example?level=DEBUG
|
...
Tip | ||
---|---|---|
| ||
For older versions of Camel that do not support the showFiles or showStreams properties above, you can set the following property instead on the CamelContext to log both stream and file bodies:
|
...
In the route below we log the incoming orders at DEBUG
level before the order is processed:
Code Block | ||||
---|---|---|---|---|
| ||||
from("activemq:orders").to("log:com.mycompany.order?level=DEBUG").to("bean:processOrder");
|
Or using Spring XML to define the route:
Code Block | ||||
---|---|---|---|---|
| ||||
<route>
<from uri="activemq:orders"/>
<to uri="log:com.mycompany.order?level=DEBUG"/>
<to uri="bean:processOrder"/>
</route>
|
...
In the route below we log the incoming orders at INFO
level before the order is processed.
Code Block | ||||
---|---|---|---|---|
| ||||
from("activemq:orders").
to("log:com.mycompany.order?showAll=true&multiline=true").to("bean:processOrder");
|
...
In the route below we log the throughput of the incoming orders at DEBUG
level grouped by 10 messages.
Code Block | ||||
---|---|---|---|---|
| ||||
from("activemq:orders").
to("log:com.mycompany.order?level=DEBUG&groupSize=10").to("bean:processOrder");
|
...
This 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.
Code Block | ||||
---|---|---|---|---|
| ||||
from("activemq:orders").
to("log:com.mycompany.order?level=DEBUG&groupInterval=10000&groupDelay=60000&groupActiveOnly=false").to("bean:processOrder");
|
The following will be logged:
Code Block |
---|
"Received: 1000 new messages, with total 2000 so far. Last group took: 10000 millis which is: 100 messages per second. average: 100"
|
...
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:
Code Block |
---|
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]
|
...
Explicitly instantiating the LogComponent in your Registry:
Code Block |
---|
<bean name="log" class="org.apache.camel.component.log.LogComponent">
<property name="exchangeFormatter" ref="myCustomFormatter" />
</bean>
|
...
Simply by registering a bean with the name logFormatter
; the Log Component is intelligent enough to pick it up automatically.
Code Block |
---|
<bean name="logFormatter" class="com.xyz.MyCustomExchangeFormatter" />
|
...
From Camel 2.11.2/2.12 onwards when using a custom log formatter, you can specify parameters in the log uri, which gets configured on the custom log formatter. Though when you do that you should define the "logForamtterlogFormatter" as prototype scoped so its not shared if you have different parameters, eg:
Code Block |
---|
<bean name="logFormatter" class="com.xyz.MyCustomExchangeFormatter" scope="prototype"/>
|
And then we can have Camel routes using the log uri with different options:
Code Block |
---|
<to uri="log:foo?param1=foo&param2=100"/>
...
<to uri="log:bar?param1=bar&param2=200"/>
|
Include Page | ||||
---|---|---|---|---|
|
- Tracer
- How do I use log4j
- How do I use Java 1.4 logging
- LogEIP for using
log
directly in the DSL for human logs.