Wiki Markup |
---|
h2. Log Component |
...
The *log:* component logs message exchanges to the underlying logging mechanism. |
...
{include |
...
:Uses Commons |
...
URI format
Code Block |
---|
Logging} h3. URI format {code} log:loggingCategory[?options] {code} 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: |
...
{code |
} log:org.apache.camel.example?level=DEBUG {code} 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. |
...
{tip | ||
:title | =Also a log in the DSL | |
Code Block | ||
---|---|---|
java | java | } In *Camel 2.2* onwards there is a {{log}} directly in the DSL, but it has a different purpose. Its meant for lightweight and human logs. See more details at [LogEIP. |
Options
Option | Default | Type | Description |
---|---|---|---|
| | | Logging level to use. Possible values: |
| | | An integer that specifies a group size for throughput logging. By default, regular logging is used. |
Formatting
The log formats the execution of exchanges to log lines.
By default, the log uses LogFormatter
to format the log output, where LogFormatter
has the following options:
Option | Default | Description |
---|---|---|
| | Quick option for turning all options on. (multiline, maxChars has to be manually set if to be used) |
| | Show the unique exchange ID. |
| | Camel 2.3: Shows the Message Exchange Pattern (or MEP for short). |
| | Show the exchange properties. |
| | Show the In message headers. |
| | Show the In body Java type. |
| | Show the In body. |
| | If the exchange has an Out message, show the Out message. |
| | Camel 2.0: If the exchange has an exception, show the exception message (no stack trace). |
| | Camel 2.0: If the exchange has a caught exception, show the exception message (no stack trace). A caught exception is stored as a property on the exchange and for instance a |
| | Camel 2.0: Show the stack trace, if an exchange has an exception. |
| | Camel 2.1: Whether Camel should show |
| | If |
|
| Camel 2.0: Limits the number of characters logged per line. |
Regular logger sample
In the route below we log the incoming orders at DEBUG
level before the order is processed:
]. {tip} h3. Options || Option || Default || Type || Description || | {{level}} | {{INFO}} | {{String}} | Logging level to use. Possible values: {{FATAL}}, {{ERROR}}, {{WARN}}, {{INFO}}, {{DEBUG}}, {{TRACE}}, {{OFF}} | | {{groupSize}} | {{null}} | {{Integer}} | An integer that specifies a group size for throughput logging. By default, regular logging is used. | h3. Formatting The log formats the execution of exchanges to log lines. By default, the log uses {{LogFormatter}} to format the log output, where {{LogFormatter}} has the following options: {div:class=confluenceTableSmall} || Option || Default || Description || | {{showAll}} | {{false}} | Quick option for turning all options on. (multiline, maxChars has to be manually set if to be used) | | {{showExchangeId}} | {{false}} | Show the unique exchange ID. | | {{showExchangePattern}} | {{true}} | *Camel 2.3:* Shows the Message Exchange Pattern (or MEP for short). | | {{showProperties}} | {{false}} | Show the exchange properties. | | {{showHeaders}} | {{false}} | Show the In message headers. | | {{showBodyType}} | {{true}} | Show the In body Java type. | | {{showBody}} | {{true}} | Show the In body. | | {{showOut}} | {{false}} | If the exchange has an Out message, show the Out message. | | {{showException}} | {{false}} | *Camel 2.0:* If the exchange has an exception, show the exception message (no stack trace). | | {{showCaughtException}} | {{false}} | *Camel 2.0:* If the exchange has a caught exception, show the exception message (no stack trace). A caught exception is stored as a property on the exchange and for instance a {{doCatch}} can catch exceptions. See [Try Catch Finally]. | | {{showStackTrace}} | {{false}} | *Camel 2.0:* Show the stack trace, if an exchange has an exception. | | {{showFuture}} | {{false}} | *Camel 2.1:* Whether Camel should show {{java.util.concurrent.Future}} bodies or not. If enabled Camel could potentially wait until the {{Future}} task is done. Will by default not wait. | | {{multiline}} | {{false}} | If {{true}}, each piece of information is logged on a new line. | | {{maxChars}} | | *Camel 2.0:* Limits the number of characters logged per line. | {div} h3. Regular logger sample In the route below we log the incoming orders at {{DEBUG}} level before the order is processed: {code:java} from("activemq:orders").to("log:com.mycompany.order?level=DEBUG").to("bean:processOrder"); {code} Or using Spring XML to define the route: |
...
{code | ||
:xml | xml | } <route> <from uri="activemq:orders"/> <to uri="log:com.mycompany.order?level=DEBUG"/> <to uri="bean:processOrder"/> </route> |
Regular logger with formatter sample
In the route below we log the incoming orders at INFO
level before the order is processed.
Code Block | ||
---|---|---|
java | java | {code} h3. Regular logger with formatter sample In the route below we log the incoming orders at {{INFO}} level before the order is processed. {code:java} from("activemq:orders"). to("log:com.mycompany.order?showAll=true&multiline=true").to("bean:processOrder"); |
Throughput logger sample
In the route below we log the throughput of the incoming orders at DEBUG
level grouped by 10 messages.
Code Block | ||
---|---|---|
java | java |
{code}
h3. Throughput logger sample
In the route below we log the throughput of the incoming orders at {{DEBUG}} level grouped by 10 messages.
{code:java}
from("activemq:orders").
to("log:com.mycompany.order?level=DEBUG?groupSize=10").to("bean:processOrder");
|
...
{code} {include:Endpoint See |
...
Also}
* [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.
|