camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From conflue...@apache.org
Subject [CONF] Apache Camel > Log
Date Mon, 01 Aug 2011 13:49:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/2042/9/1/_/styles/combined.css?spaceKey=CAMEL&amp;forWysiwyg=true"
type="text/css">
    </head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
    <h2><a href="https://cwiki.apache.org/confluence/display/CAMEL/Log">Log</a></h2>
    <h4>Page <b>edited</b> by             <a href="https://cwiki.apache.org/confluence/display/~davsclaus">Claus
Ibsen</a>
    </h4>
        <br/>
                         <h4>Changes (1)</h4>
                                 
    
<div id="page-diffs">
                    <table class="diff" cellpadding="0" cellspacing="0">
    
            <tr><td class="diff-snipped" >...<br></td></tr>
            <tr><td class="diff-unchanged" >| {{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]. | <br>| {{showStackTrace}} | {{false}}
| *Camel 2.0:* Show the stack trace, if an exchange has an exception. Only effective if one
of {{showAll}}, {{showException}} or {{showCaughtException}} are enabled. |  <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">|
{{showFiles}} | {{false}} | *Camel 2.9:* Whether Camel should show file bodies or not (eg
such as java.io.File). |  <br></td></tr>
            <tr><td class="diff-unchanged" >| {{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.
| <br>| {{showStreams}} | {{false}} | *Camel 2.8:* Whether Camel should show stream
bodies or not (eg such as java.io.InputStream). Beware if you enable this option then you
may not be able later to access the message body as the stream have already been read by this
logger. To remedy this you have to use [Stream Caching]. |  <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="Log-LogComponent"></a>Log Component</h2>

<p>The <b>log:</b> component logs message exchanges to the underlying logging
mechanism.</p>

<p><b>Camel 2.7 or better</b> uses <a href="http://www.slf4j.org/" class="external-link"
rel="nofollow">sfl4j</a> which allows you to configure logging via, among others:</p>
<ul>
	<li><a href="http://logging.apache.org/log4j/" class="external-link" rel="nofollow">Log4j</a></li>
	<li><a href="http://logback.qos.ch/" class="external-link" rel="nofollow">Logback</a></li>
	<li><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/package-summary.html"
class="external-link" rel="nofollow">JDK Util Logging logging</a></li>
</ul>


<p><b>Camel 2.6 or lower</b> uses <a href="http://commons.apache.org/logging/"
class="external-link" rel="nofollow">commons-logging</a> which allows you to configure
logging via, among others:</p>
<ul>
	<li><a href="http://logging.apache.org/log4j/" class="external-link" rel="nofollow">Log4j</a></li>
	<li><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/package-summary.html"
class="external-link" rel="nofollow">JDK Util Logging logging</a></li>
	<li>SimpleLog - a simple provider in commons-logging</li>
</ul>


<p>Refer to the <a href="http://commons.apache.org/logging/commons-logging-1.1.1/guide.html"
class="external-link" rel="nofollow">commons-logging user guide</a> for a more complete
overview of how to use and configure commons-logging.</p>


<h3><a name="Log-URIformat"></a>URI format</h3>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
log:loggingCategory[?options]
</pre>
</div></div>

<p>Where <b>loggingCategory</b> is the name of the logging category to use.
You can append query options to the URI in the following format, <tt>?option=value&amp;option=value&amp;...</tt></p>

<p>For example, a log endpoint typically specifies the logging level using the <tt>level</tt>
option, as follows:</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
log:org.apache.camel.example?level=DEBUG
</pre>
</div></div>

<p>The default logger logs every exchange (<em>regular logging</em>). But
Camel also ships with the <tt>Throughput</tt> logger, which is used whenever the
<tt>groupSize</tt> option is specified.</p>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Also a log in the DSL</b><br
/>In <b>Camel 2.2</b> onwards there is a <tt>log</tt> directly
in the DSL, but it has a different purpose. Its meant for lightweight and human logs. See
more details at <a href="/confluence/display/CAMEL/LogEIP" title="LogEIP">LogEIP</a>.</td></tr></table></div>

<h3><a name="Log-Options"></a>Options</h3>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Type </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>level</tt> </td>
<td class='confluenceTd'> <tt>INFO</tt> </td>
<td class='confluenceTd'> <tt>String</tt> </td>
<td class='confluenceTd'> Logging level to use. Possible values: <tt>FATAL</tt>,
<tt>ERROR</tt>, <tt>WARN</tt>, <tt>INFO</tt>, <tt>DEBUG</tt>,
<tt>TRACE</tt>, <tt>OFF</tt> </td>
</tr>
<tr>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> Throughput logging options. By default regular logging is
used. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>groupSize</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> An integer that specifies a group size for throughput logging.</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>groupInterval</tt> </td>
<td class='confluenceTd'> <tt>null</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6</b>: If specified will group message
stats by this time interval (in millis) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>groupDelay</tt> </td>
<td class='confluenceTd'> <tt>0</tt> </td>
<td class='confluenceTd'> <tt>Integer</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6</b>: Set the initial delay for stats
(in millis) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>groupActiveOnly</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <tt>boolean</tt> </td>
<td class='confluenceTd'> <b>Camel 2.6</b>: If true, will hide stats when
no new messages have been received for a time interval, if false, show stats regardless of
message traffic </td>
</tr>
</tbody></table>
</div>
</div>
<p><b>note</b>: groupDelay and groupActiveOnly are only applicable when
using groupInterval</p>



<h3><a name="Log-Formatting"></a>Formatting</h3>
<p>The log formats the execution of exchanges to log lines. <br/>
By default, the log uses <tt>LogFormatter</tt> to format the log output, where
<tt>LogFormatter</tt> has the following options:</p>
<div class="confluenceTableSmall"><div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'> Option </th>
<th class='confluenceTh'> Default </th>
<th class='confluenceTh'> Description </th>
</tr>
<tr>
<td class='confluenceTd'> <tt>showAll</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Quick option for turning all options on. (multiline, maxChars
has to be manually set if to be used) </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showExchangeId</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Show the unique exchange ID. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showExchangePattern</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> <b>Camel 2.3:</b> Shows the Message Exchange Pattern
(or MEP for short). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showProperties</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Show the exchange properties. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showHeaders</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> Show the In message headers. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showBodyType</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Show the In body Java type. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showBody</tt> </td>
<td class='confluenceTd'> <tt>true</tt> </td>
<td class='confluenceTd'> Show the In body. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showOut</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If the exchange has an Out message, show the Out message.
</td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> If the exchange has an exception,
show the exception message (no stack trace). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showCaughtException</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> 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 <tt>doCatch</tt> can catch exceptions.
See <a href="/confluence/display/CAMEL/Try+Catch+Finally" title="Try Catch Finally">Try
Catch Finally</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showStackTrace</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Show the stack trace, if an
exchange has an exception. Only effective if one of <tt>showAll</tt>, <tt>showException</tt>
or <tt>showCaughtException</tt> are enabled. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showFiles</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.9:</b> Whether Camel should show file
bodies or not (eg such as java.io.File). </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showFuture</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.1:</b> Whether Camel should show <tt>java.util.concurrent.Future</tt>
bodies or not. If enabled Camel could potentially wait until the <tt>Future</tt>
task is done. Will by default not wait. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>showStreams</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> <b>Camel 2.8:</b> Whether Camel should show stream
bodies or not (eg such as java.io.InputStream). Beware if you enable this option then you
may not be able later to access the message body as the stream have already been read by this
logger. To remedy this you have to use <a href="/confluence/display/CAMEL/Stream+caching"
title="Stream caching">Stream caching</a>. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>multiline</tt> </td>
<td class='confluenceTd'> <tt>false</tt> </td>
<td class='confluenceTd'> If <tt>true</tt>, each piece of information is
logged on a new line. </td>
</tr>
<tr>
<td class='confluenceTd'> <tt>maxChars</tt> </td>
<td class='confluenceTd'>&nbsp;</td>
<td class='confluenceTd'> <b>Camel 2.0:</b> Limits the number of characters
logged per line. </td>
</tr>
</tbody></table>
</div>
</div>

<div class='panelMacro'><table class='tipMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/check.gif" width="16" height="16"
align="absmiddle" alt="" border="0"></td><td><b>Logging stream bodies</b><br
/>Camel will by default <b>not</b> log stream or files bodies. You can force
Camel to log those by setting the property on the <a href="/confluence/display/CAMEL/CamelContext"
title="CamelContext">CamelContext</a> properties
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
camelContext.getProperties().put(Exchange.LOG_DEBUG_BODY_STREAMS, <span class="code-keyword">true</span>);
</pre>
</div></div></td></tr></table></div>


<h3><a name="Log-Regularloggersample"></a>Regular logger sample</h3>
<p>In the route below we log the incoming orders at <tt>DEBUG</tt> level
before the order is processed:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:orders"</span>).to(<span class="code-quote">"log:com.mycompany.order?level=DEBUG"</span>).to(<span
class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

<p>Or using Spring XML to define the route:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-xml">
  <span class="code-tag">&lt;route&gt;</span>
    <span class="code-tag">&lt;from uri=<span class="code-quote">"activemq:orders"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"log:com.mycompany.order?level=DEBUG"</span>/&gt;</span>
    <span class="code-tag">&lt;to uri=<span class="code-quote">"bean:processOrder"</span>/&gt;</span>
  <span class="code-tag">&lt;/route&gt;</span> 
</pre>
</div></div>

<h3><a name="Log-Regularloggerwithformattersample"></a>Regular logger with
formatter sample</h3>
<p>In the route below we log the incoming orders at <tt>INFO</tt> level
before the order is processed.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:orders"</span>).
    to(<span class="code-quote">"log:com.mycompany.order?showAll=<span class="code-keyword">true</span>&amp;multiline=<span
class="code-keyword">true</span>"</span>).to(<span class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

<h3><a name="Log-ThroughputloggerwithgroupSizesample"></a>Throughput logger
with groupSize sample</h3>
<p>In the route below we log the throughput of the incoming orders at <tt>DEBUG</tt>
level grouped by 10 messages.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:orders"</span>).
    to(<span class="code-quote">"log:com.mycompany.order?level=DEBUG?groupSize=10"</span>).to(<span
class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

<h3><a name="Log-ThroughputloggerwithgroupIntervalsample"></a>Throughput
logger with groupInterval sample</h3>

<p>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.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
from(<span class="code-quote">"activemq:orders"</span>).
to(<span class="code-quote">"log:com.mycompany.order?level=DEBUG?groupInterval=10000&amp;groupDelay=60000&amp;groupActiveOnly=<span
class="code-keyword">false</span>"</span>).to(<span class="code-quote">"bean:processOrder"</span>);
</pre>
</div></div>

<p>The following will be logged:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="code-java">
<span class="code-quote">"Received: 1000 <span class="code-keyword">new</span>
messages, with total 2000 so far. Last group took: 10000 millis which is: 100 messages per
second. average: 100"</span>
</pre>
</div></div>


<h3><a name="Log-SeeAlso"></a>See Also</h3>
<ul>
	<li><a href="/confluence/display/CAMEL/Configuring+Camel" title="Configuring Camel">Configuring
Camel</a></li>
	<li><a href="/confluence/display/CAMEL/Component" title="Component">Component</a></li>
	<li><a href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a></li>
	<li><a href="/confluence/display/CAMEL/Getting+Started" title="Getting Started">Getting
Started</a></li>
</ul>

<ul>
	<li><a href="/confluence/display/CAMEL/Tracer" title="Tracer">Tracer</a></li>
	<li><a href="/confluence/display/CAMEL/How+do+I+use+log4j" title="How do I use log4j">How
do I use log4j</a></li>
	<li><a href="/confluence/display/CAMEL/How+do+I+use+Java+1.4+logging" title="How
do I use Java 1.4 logging">How do I use Java 1.4 logging</a></li>
	<li><a href="/confluence/display/CAMEL/LogEIP" title="LogEIP">LogEIP</a>
for using <tt>log</tt> directly in the DSL for human logs.</li>
</ul>


    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;">
            <a href="https://cwiki.apache.org/confluence/users/viewnotifications.action"
class="grey">Change Notification Preferences</a>
        </div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Log">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=63040&revisedVersion=27&originalVersion=26">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/Log?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message