Modified: websites/production/camel/content/tracer.html
==============================================================================
--- websites/production/camel/content/tracer.html (original)
+++ websites/production/camel/content/tracer.html Fri Aug 25 08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: Tracer
@@ -86,43 +75,22 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="Tracer-TracerInterceptor">Tracer
Interceptor</h2><div class="confluence-information-macro
confluence-information-macro-warning"><span class="aui-icon aui-icon-small
aui-iconfont-error confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Implementing custom tracing via
TracingInterceptor has been deprecated. However turning tracing on via
setTracing(true) is okay.</p></div></div><p> </p><p>Camel's tracer
interceptor can be used for logging, by default at the
<strong><code>INFO</code></strong> level, a route's execution. The tracer is an
instance of
<strong><code>org.apache.camel.spi.InterceptStrategy</code></strong>. It can be
applied to either a <strong><code>DefaultCamelContext</code></strong> or a
<strong><code>SpringCamelContext</code></strong> to ensure that there is
a <strong><code>TracerInterceptor</code></strong> created for every node
in the route. The tracer's logging can be
enabled/disabled dynamically by calling its
<strong><code>setEnabled</code></strong> method.</p><div
class="confluence-information-macro confluence-information-macro-tip"><p
class="title">Logging dependencies</p><span class="aui-icon aui-icon-small
aui-iconfont-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Checkout which <a shape="rect"
href="camel-jar-dependencies.html">dependencies</a> are required by Camel for
logging purpose.</p></div></div><div class="confluence-information-macro
confluence-information-macro-information"><span class="aui-icon aui-icon-small
aui-iconfont-info confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>From <strong>Camel 2.12</strong>:
the <a shape="rect" href="camelcontext.html">CamelContext</a> must be
explicitly configured for tracing:</p><ul><li>XML: 
<strong><code><camelContext trace="true"
...></code></strong></li><li>Java: <strong><code>camelCo
ntext.setTracing(true)</code></strong>.</li></ul></div></div><h3
id="Tracer-Options">Options</h3><div class="confluenceTableSmall"><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>destinationUri</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Optional destination URI to
route <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventExchange.html">TraceEventExchange</a>
containing <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/inter
ceptor/TraceEventMessage.html">TraceEventMessage</a> with details about the
trace. Can be used for custom processing to store traces in database using <a
shape="rect" href="jpa.html">JPA</a>.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>enabled</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Enable/disable the
tracer.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>formatter</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Sets the Trace Formatter to use.</p><p>Default:
<strong><code>org.apache.camel.processor.interceptor.DefaultTraceFormatter</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>jpaTraceEventMessageClassName</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></
p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel
2.3:</strong> Fully qualified class name for a custom
<strong><code>org.apache.camel.processor.interceptor.TraceEventMessage</code></strong>
class which contains the traced information.</p><p>For example you can use
your custom JPA @Entity class to store traced information in a database
according to your schema layout.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>logLevel</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>INFO</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>The logging level to use:
<strong><code>FATAL</code>, <code>ERROR</code></strong>,
<strong><code>WARN</code>, <code>INFO</code></strong>,
<strong><code>DEBUG</code>,
<code>TRACE</code></strong>, <strong><code>OFF</code></strong></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>logName</code></p></td><td colspan="1"
rowspan="1" class="conflue
nceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The log name to use.</p><p>Default:
<strong><code>org.apache.camel.processor.interceptor.TraceInterceptor</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>logStackTrace</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Controls whether the stack trace of a
traced exception should be logged. If <strong><code>false</code></strong>
only the exception's class and message are logged.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>traceFilter</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>An Exchange <a shape="rect"
href="predicate.html">Predicate</a> to filter the tracing.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>
traceInterceptors</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Enable/disable tracing of
interceptors.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>traceExceptions</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Enable/disable tracing of an exception
thrown during the processing of an Exchange.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>traceHandler</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.3:</strong> To
use a custom
<strong><code>org.apache.camel.processor.interceptor.TraceEventHandler</code></strong>
where you can control what happens when a trace event
occurs.</p></td></tr><tr><td colspan="1" rowspan="1" cl
ass="confluenceTd"><p><code>traceInterceptorFactory</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.3:</strong> To
use a custom
<strong><code>org.apache.camel.processor.interceptor.TraceInterceptorFactory</code></strong>
where you can create the runtime trace instance which does the actual tracing.
It should be a <strong><code>Processor</code></strong> instance.</p><p>Default:
<strong><code>org.apache.camel.processor.interceptor.TraceInterceptor</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>traceOutExchanges</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Enable/disable fine grained tracing, using
a callback, for both <strong><code>IN</code></strong> (before)
and <strong><code>OUT</code></strong> (after).</p><p>By defaul
t only one trace callback is executed.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>useJpa</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>To use a
<strong><code>JpaTraceEventMessage</code></strong> from
<strong>camel-jpa</strong> component as the
<strong><code>TraceEventMessage</code></strong>. This requires that
<strong>camel-jpa.jar</strong> is on the
classpath.</p></td></tr></tbody></table></div></div>
-
-
-<h3 id="Tracer-Formatting">Formatting</h3><p>The tracer formats the execution
of exchanges to log lines. They are logged
at <strong><code>INFO</code></strong> level in the log category:
<strong><code>org.apache.camel.processor.interceptor.TraceInterceptor</code></strong>.
By default the tracer uses:
<strong><code>org.apache.camel.processor.interceptor.DefaultTraceFormatter</code></strong>
to format the log
line.</p><p><strong><code>DefaultTraceFormatter</code></strong> has the
following options:</p><div class="confluenceTableSmall"><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>breadCrumbLength</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td col
span="1" rowspan="1" class="confluenceTd"><p>Fixed length of the bread
crumb. </p><p><code>0</code> = no fixed length.</p><p>Setting a value to
e.g. <code>80</code> allows the tracer logs to be aligned for easier
reading.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>maxChars</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Limits the number of chars logged per line.</p><p>From
<strong>Camel 2.9</strong>: the default value is
<strong><code>10000</code>.</strong></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>multiline</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.18:</strong> If
<strong><code>true</code></strong> each piece of information is logged on a new
line.</p></td></tr><tr><td colspan="1" rowspan="1" class="confl
uenceTd"><p><code>nodeLength</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>0</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Fixed length of the node. </p><p><code>0</code> =
no fixed length.</p><p>Setting a value to e.g. <code>40</code> allows the
tracer logs to be aligned for easier reading.</p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>showBody</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Output
the <strong><code>IN</code></strong> body.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>showBodyType</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Output
the <strong><code>IN</code></strong> body Java type.</p></td></tr><tr><td
colspan="1" rowspan="1" class="confluenceTd
"><p><code>showBreadCrumb</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>true</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Outputs the unique UnitOfWork for the
exchange.</p><p>Can be used for correlation to identify a particular
Exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showException</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Output the exception if the processing of
an Exchange has failed.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showExchangeId</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Enable/disable the output of an Exchange's
unique <strong><code>id</code></strong>.</p><p>Currently the breadcrumb is
sufficient.</p></td></tr><tr><td colspan="1" rowspan="1
" class="confluenceTd"><p><code>showExchangePattern</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Output the Message Exchange
Pattern (MEP).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showHeaders</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Output
the <strong><code>IN</code></strong> message headers.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>showNode</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Previous and destination
node.</p><p>Displayed as: <strong><code>from ->
to</code></strong>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showOutBody</code></p></td><td colspan="1"
rowspan="1" clas
s="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Output the <strong><code>OUT</code></strong> (if
any) body.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showOutBodyType</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Output
the <strong><code>OUT</code></strong> (if any) body Java
type.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showOutHeaders</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Output
the <strong><code>OUT</code></strong> (if any) message
headers.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showProperties</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="
1" class="confluenceTd"><p>Output the Exchange's
properties.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showRouteId</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> output
the <strong><code>id</code></strong> of the route.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>showShortExchangeId</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>To output the Exchange's unique
<strong><code>id</code></strong> in short form, without the
hostname.</p></td></tr></tbody></table></div></div>
-
-
-<div class="confluence-information-macro confluence-information-macro-tip"><p
class="title">Logging stream bodies</p><span class="aui-icon aui-icon-small
aui-iconfont-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>From <strong>Camel 2.8</strong>:
the Camel <a shape="rect" href="tracer.html">Tracer</a> will by default
<em>not</em> log stream or files bodies. To force Camel to log these set the
following property on the <a shape="rect"
href="camelcontext.html">CamelContext</a> properties:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[camelContext.getProperties().put(Exchange.LOG_DEBUG_BODY_STREAMS,
true);
-]]></script>
-</div></div></div></div><p>Example:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ID-claus-acer/4412-1222625653890/2-0 ->
to(mock:a) , Pattern:InOnly , Headers:{to=James} ,
BodyType:String , Body:Hello London
-]]></script>
-</div></div><p>where:</p><ul><li><strong><code>ID-claus-acer/3690-1214458315718/2-0</code></strong>
is the breadcrumb with the unique correlation id.</li><li><strong>
<code>node3</code></strong> is the id of the node in the route path. Always
displayed.</li><li><strong> <code>To[mock:a]</code></strong> is the destination
node.</li><li><strong> <code>InOnly</code></strong> is the exchange pattern. Is
always shown.</li><li>Then the rest is properties, headers and the
body.</li></ul><h4 id="Tracer-Showingfromandto">Showing <code>from</code>
and <code>to</code></h4><p>The trace log will output both the from and to
so you can see where the Exchange came from, such as:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[>>> direct:start -->
process(MyProcessor)
+<div class="wiki-content maincontent"><h2 id="Tracer-TracerInterceptor">Tracer
Interceptor</h2><rich-text-body><p>Implementing custom tracing via
TracingInterceptor has been deprecated. However turning tracing on via
setTracing(true) is okay.</p></rich-text-body><p> </p><p>Camel's tracer
interceptor can be used for logging, by default at the
<strong><code>INFO</code></strong> level, a route's execution. The tracer is an
instance of
<strong><code>org.apache.camel.spi.InterceptStrategy</code></strong>. It can be
applied to either a <strong><code>DefaultCamelContext</code></strong> or a
<strong><code>SpringCamelContext</code></strong> to ensure that there is
a <strong><code>TracerInterceptor</code></strong> created for every node
in the route. The tracer's logging can be enabled/disabled dynamically by
calling its <strong><code>setEnabled</code></strong> method.</p><parameter
ac:name="title">Logging dependencies</parameter><rich-text-body><p>Checkout
which <a shape="rect
" href="camel-jar-dependencies.html">dependencies</a> are required by Camel
for logging purpose.</p></rich-text-body><rich-text-body><p>From <strong>Camel
2.12</strong>: the <a shape="rect" href="camelcontext.html">CamelContext</a>
must be explicitly configured for tracing:</p><ul><li>XML: 
<strong><code><camelContext trace="true"
...></code></strong></li><li>Java:
<strong><code>camelContext.setTracing(true)</code></strong>.</li></ul></rich-text-body><h3
id="Tracer-Options">Options</h3><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>destinationUri</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><
p><code>null</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Optional destination URI to route <a shape="rect"
class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventExchange.html">TraceEventExchange</a>
containing <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventMessage.html">TraceEventMessage</a>
with details about the trace. Can be used for custom processing to store
traces in database using <a shape="rect"
href="jpa.html">JPA</a>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>enabled</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Enable/disable the
tracer.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>formatter</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Sets the Trace Formatter to
use.</p><p>Default:
<strong><code>org.apache.camel.processor.interceptor.DefaultTraceFormatter</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>jpaTraceEventMessageClassName</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.3:</strong>
Fully qualified class name for a custom
<strong><code>org.apache.camel.processor.interceptor.TraceEventMessage</code></strong>
class which contains the traced information.</p><p>For example you can use
your custom JPA @Entity class to store traced information in a database
according to your schema layout.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>logLevel</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>
INFO</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>The
logging level to use: <strong><code>FATAL</code>, <code>ERROR</code></strong>,
<strong><code>WARN</code>, <code>INFO</code></strong>,
<strong><code>DEBUG</code>,
<code>TRACE</code></strong>, <strong><code>OFF</code></strong></p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>logName</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>The log name to use.</p><p>Default:
<strong><code>org.apache.camel.processor.interceptor.TraceInterceptor</code></strong>.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>logStackTrace</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Controls whether the stack trace of a
traced exception should be logged. If <strong><code>false</code></strong>
only the exception's class and message are logged.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>traceFilter</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>An Exchange <a shape="rect"
href="predicate.html">Predicate</a> to filter the tracing.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>traceInterceptors</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Enable/disable tracing of
interceptors.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>traceExceptions</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Enable/disable tracing of an exception
thrown during the processing of an Exchange.</p></td></tr><tr><td colspa
n="1" rowspan="1"
class="confluenceTd"><p><code>traceHandler</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.3:</strong> To use a custom
<strong><code>org.apache.camel.processor.interceptor.TraceEventHandler</code></strong>
where you can control what happens when a trace event
occurs.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>traceInterceptorFactory</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>null</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.3:</strong> To
use a custom
<strong><code>org.apache.camel.processor.interceptor.TraceInterceptorFactory</code></strong>
where you can create the runtime trace instance which does the actual tracing.
It should be a <strong><code>Processor</code></strong> instance.</p><p>Default:
<strong><code>org.apache.camel.processor.interceptor.Trace
Interceptor</code></strong>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>traceOutExchanges</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Enable/disable fine grained tracing, using
a callback, for both <strong><code>IN</code></strong> (before)
and <strong><code>OUT</code></strong> (after).</p><p>By default only one
trace callback is executed.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>useJpa</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>false</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>To use a
<strong><code>JpaTraceEventMessage</code></strong> from
<strong>camel-jpa</strong> component as the
<strong><code>TraceEventMessage</code></strong>. This requires that
<strong>camel-jpa.jar</strong> is on the
classpath.</p></td></tr></tbody></table></div></rich-text-body><h3
id="Tracer-Formatting">Formatting</h3><p>The tracer formats the execution of
exchanges to log lines. They are logged
at <strong><code>INFO</code></strong> level in the log category:
<strong><code>org.apache.camel.processor.interceptor.TraceInterceptor</code></strong>.
By default the tracer uses:
<strong><code>org.apache.camel.processor.interceptor.DefaultTraceFormatter</code></strong>
to format the log
line.</p><p><strong><code>DefaultTraceFormatter</code></strong> has the
following options:</p><parameter
ac:name="class">confluenceTableSmall</parameter><rich-text-body><div
class="table-wrap"><table class="confluenceTable"><tbody><tr><th colspan="1"
rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1"
class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>breadCrumbLength</code></p></td><td
colspan="1" rowspan="1" class="confluenc
eTd"><p><code>0</code></p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Fixed length of the bread
crumb. </p><p><code>0</code> = no fixed length.</p><p>Setting a value to
e.g. <code>80</code> allows the tracer logs to be aligned for easier
reading.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>maxChars</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p> </p></td><td colspan="1" rowspan="1"
class="confluenceTd"><p>Limits the number of chars logged per line.</p><p>From
<strong>Camel 2.9</strong>: the default value is
<strong><code>10000</code>.</strong></p></td></tr><tr><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>multiline</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><strong>Camel 2.18:</strong> If
<strong><code>true</code></strong> each piece of information is logged on a new
line.</p></td></tr><tr><t
d colspan="1" rowspan="1"
class="confluenceTd"><p><code>nodeLength</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>0</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Fixed length of the
node. </p><p><code>0</code> = no fixed length.</p><p>Setting a value to
e.g. <code>40</code> allows the tracer logs to be aligned for easier
reading.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showBody</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Output
the <strong><code>IN</code></strong> body.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>showBodyType</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Output
the <strong><code>IN</code></strong> body Java type.</p></td></tr><tr><td
colsp
an="1" rowspan="1"
class="confluenceTd"><p><code>showBreadCrumb</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Outputs the unique UnitOfWork for the
exchange.</p><p>Can be used for correlation to identify a particular
Exchange.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showException</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Output the exception if the processing of
an Exchange has failed.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showExchangeId</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Enable/disable the output of an Exchange's
unique <strong><code>id</code></strong>.</p><p>Currently the breadcrumb is
sufficient.</p></
td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showExchangePattern</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>Output the Message Exchange
Pattern (MEP).</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showHeaders</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Output
the <strong><code>IN</code></strong> message headers.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>showNode</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p>Previous and destination
node.</p><p>Displayed as: <strong><code>from ->
to</code></strong>.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showOutBody</code></p
></td><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>false</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p>Output
>the <strong><code>OUT</code></strong> (if any)
>body.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>showOutBodyType</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p>Output
>the <strong><code>OUT</code></strong> (if any) body Java
>type.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>showOutHeaders</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
>colspan="1" rowspan="1" class="confluenceTd"><p>Output
>the <strong><code>OUT</code></strong> (if any) message
>headers.</p></td></tr><tr><td colspan="1" rowspan="1"
>class="confluenceTd"><p><code>showProperties</code></p></td><td colspan="1"
>rowspan="1" class="confluenceTd"><p><code>false</c
ode></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>Output the
Exchange's properties.</p></td></tr><tr><td colspan="1" rowspan="1"
class="confluenceTd"><p><code>showRouteId</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><code>true</code></p></td><td colspan="1"
rowspan="1" class="confluenceTd"><p><strong>Camel 2.8:</strong> output
the <strong><code>id</code></strong> of the route.</p></td></tr><tr><td
colspan="1" rowspan="1"
class="confluenceTd"><p><code>showShortExchangeId</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p><code>false</code></p></td><td
colspan="1" rowspan="1" class="confluenceTd"><p>To output the Exchange's unique
<strong><code>id</code></strong> in short form, without the
hostname.</p></td></tr></tbody></table></div></rich-text-body><parameter
ac:name="title">Logging stream bodies</parameter><rich-text-body><p>From
<strong>Camel 2.8</strong>: the Camel <a shape="rect"
href="tracer.html">Tracer</a> will by defa
ult <em>not</em> log stream or files bodies. To force Camel to log these set
the following property on the <a shape="rect"
href="camelcontext.html">CamelContext</a> properties:</p><parameter
ac:name="language">java</parameter><plain-text-body>camelContext.getProperties().put(Exchange.LOG_DEBUG_BODY_STREAMS,
true);
+</plain-text-body></rich-text-body><p>Example:</p><plain-text-body>ID-claus-acer/4412-1222625653890/2-0
-> to(mock:a) , Pattern:InOnly , Headers:{to=James} ,
BodyType:String , Body:Hello London
+</plain-text-body><p>where:</p><ul><li><strong><code>ID-claus-acer/3690-1214458315718/2-0</code></strong>
is the breadcrumb with the unique correlation id.</li><li><strong>
<code>node3</code></strong> is the id of the node in the route path. Always
displayed.</li><li><strong> <code>To[mock:a]</code></strong> is the destination
node.</li><li><strong> <code>InOnly</code></strong> is the exchange pattern. Is
always shown.</li><li>Then the rest is properties, headers and the
body.</li></ul><h4 id="Tracer-Showingfromandto">Showing <code>from</code>
and <code>to</code></h4><p>The trace log will output both the from and to
so you can see where the Exchange came from, such
as:</p><plain-text-body>>>> direct:start --> process(MyProcessor)
>>> process(MyProcessor) --> to(mock:a)
>>> to(mock:a) --> to(mock:b)
-]]></script>
-</div></div><h3 id="Tracer-Enabling">Enabling</h3><p>To enable tracer from the
main run:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[java org.apache.camel.spring.Main -t
-]]></script>
-</div></div><p>or</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[java org.apache.camel.spring.Main -trace
-]]></script>
-</div></div><p>and the tracer will be activated.</p><h3
id="Tracer-EnablinginJava">Enabling in Java</h3><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[context.setTracing(true);
-]]></script>
-</div></div><p>You can configure tracing at a higher granularity as you can
configure it on camel context and then override and set it per route as well.
For instance you could just enable the tracer for a particular route.</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[INFO TraceInterceptor -
ID-davsclaus-local-54403-1246038742624-0-0 >>> from(direct:start)
--> MyProcessor , Pattern:InOnly, Headers:{to=James}, BodyType:String,
Body:Hello London
+</plain-text-body><h3 id="Tracer-Enabling">Enabling</h3><p>To enable tracer
from the main run:</p><plain-text-body>java org.apache.camel.spring.Main -t
+</plain-text-body><p>or</p><plain-text-body>java org.apache.camel.spring.Main
-trace
+</plain-text-body><p>and the tracer will be activated.</p><h3
id="Tracer-EnablinginJava">Enabling in Java</h3><parameter
ac:name="language">java</parameter><plain-text-body>context.setTracing(true);
+</plain-text-body><p>You can configure tracing at a higher granularity as you
can configure it on camel context and then override and set it per route as
well. For instance you could just enable the tracer for a particular
route.</p><plain-text-body>INFO TraceInterceptor -
ID-davsclaus-local-54403-1246038742624-0-0 >>> from(direct:start)
--> MyProcessor , Pattern:InOnly, Headers:{to=James}, BodyType:String,
Body:Hello London
INFO TraceInterceptor - ID-davsclaus-local-54403-1246038742624-0-0
>>> MyProcessor --> mock:a , Pattern:InOnly,
Headers:{to=James}, BodyType:String, Body:Hello London
INFO TraceInterceptor - ID-davsclaus-local-54403-1246038742624-0-0
>>> mock:a --> mock:b , Pattern:InOnly,
Headers:{to=James}, BodyType:String, Body:Hello London
...
INFO TraceInterceptor - ID-davsclaus-local-54403-1246038742624-0-1
>>> from(direct:start) --> MyProcessor , Pattern:InOnly,
Headers:{from=Claus}, BodyType:String, Body:This is Copenhagen calling
INFO TraceInterceptor - ID-davsclaus-local-54403-1246038742624-0-1
>>> MyProcessor --> mock:a , Pattern:InOnly,
Headers:{from=Claus}, BodyType:String, Body:This is Copenhagen calling
INFO TraceInterceptor - ID-davsclaus-local-54403-1246038742624-0-1
>>> mock:a --> mock:b , Pattern:InOnly,
Headers:{from=Claus}, BodyType:String, Body:This is Copenhagen calling
-]]></script>
-</div></div><h3 id="Tracer-ConfiguringinJava">Configuring in
Java</h3><p>Tracer options can be configured in Java as follows:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ public void configure() throws Exception {
+</plain-text-body><h3 id="Tracer-ConfiguringinJava">Configuring in
Java</h3><p>Tracer options can be configured in Java as follows:</p><parameter
ac:name="language">java</parameter><plain-text-body> public void configure()
throws Exception {
// add tracer as an interceptor so it will log the exchange executions
at runtime
// this can aid us to understand/see how the exchanges is routed etc.
Tracer tracer = new Tracer();
@@ -130,190 +98,20 @@ INFO TraceInterceptor - ID-davsclau
formatter.getDefaultTraceFormatter().setShowNode(false);
...
getContext().addInterceptStrategy(tracer);
-]]></script>
-</div></div><h4 id="Tracer-UsingPredicatestoFilterExchanges">Using Predicates
to Filter Exchanges</h4><p>In the code below we want the tracer only to trace
if the body contains the text <strong><code>London</code></strong>. As this is
just an example can of course set any <a shape="rect"
href="predicate.html">Predicate</a> that matches your criteria:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ Tracer tracer = new Tracer();
+</plain-text-body><h4 id="Tracer-UsingPredicatestoFilterExchanges">Using
Predicates to Filter Exchanges</h4><p>In the code below we want the tracer only
to trace if the body contains the text <strong><code>London</code></strong>. As
this is just an example can of course set any <a shape="rect"
href="predicate.html">Predicate</a> that matches your criteria:</p><parameter
ac:name="">java</parameter><plain-text-body> Tracer tracer = new Tracer();
// set the level to FATAL so we can easily spot it
tracer.setLogLevel(LoggingLevel.FATAL);
// and only trace if the body contains London as text
- tracer.setTraceFilter(body().contains(constant("London")));
-]]></script>
-</div></div><h3 id="Tracer-EnablinginSpringXML">Enabling in Spring
XML</h3><p>There is now a <strong><code>trace</code></strong> attribute
you can specify on
the <strong><code><camelContext/></code></strong>.</p><p>Example:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <camelContext trace="true"
xmlns="http://activemq.apache.org/camel/schema/spring">
+ tracer.setTraceFilter(body().contains(constant("London")));
+</plain-text-body><h3 id="Tracer-EnablinginSpringXML">Enabling in Spring
XML</h3><p>There is now a <strong><code>trace</code></strong> attribute
you can specify on
the <strong><code><camelContext/></code></strong>.</p><p>Example:</p><parameter
ac:name="language">xml</parameter><plain-text-body> <camelContext
trace="true" xmlns="http://activemq.apache.org/camel/schema/spring">
...
</camelContext>
-]]></script>
-</div></div><p>You can see this in action with the <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTraceTest.java">SpringTraceTest</a>
and its <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTraceTest-context.xml">spring.xml
file</a></p><p>Another option is to just include a spring XML which defines
the Tracer bean such as the <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/main/resources/META-INF/services/org/apache/camel/spring/trace.xml">one
that is automatically included if you run the Main with -t above</a>.</p><h3
id="Tracer-ConfiguringinSpringXML">Configuring in Spring XML</h3><p>You can
configure the tracer as a Spring bean. Just add a bean with the bean class
<strong><co
de>org.apache.camel.processor.interceptor.Tracer</code></strong> and Camel
will use it as the tracer.</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<!-- we can configure the tracer by defining the tracer bean and set the
properties as we like -->
-<!-- the id name can be anything its the class that must be
org.apache.camel.processor.interceptor.Tracer -->
-<bean id="camelTracer"
class="org.apache.camel.processor.interceptor.Tracer">
- <property name="traceExceptions" value="false"/>
- <property name="traceInterceptors" value="true"/>
- <property name="logLevel" value="ERROR"/>
- <property name="logName"
value="com.mycompany.messages"/>
-</bean>
-
-<camelContext trace="true"
xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <to uri="mock:result"/>
- </route>
-</camelContext>
-]]></script>
-</div></div> <p>You can configure the formatting of tracer as a Spring
bean. Just add a bean with
the <strong><code>id="traceFormatter"</code></strong> and Camel will
lookup this <strong><code>id</code></strong> and use the associated
formatter.</p><p>Example:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<bean id="traceFormatter"
class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
- <property name="showBody" value="true"/>
- <property name="showBodyType" value="false"/>
- <property name="showBreadCrumb" value="false"/>
- <property name="maxChars" value="100"/>
-</bean>
-
-<camelContext trace="true"
xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <to uri="mock:result"/>
- </route>
-</camelContext>
-]]></script>
-</div></div><h3 id="Tracer-EnableTracingofOUTMessages">Enable Tracing
of <code>OUT</code> Messages</h3><p>To trace the messages coming out of
processing steps configure the tracer as follows:</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>Java DSL</b></div><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-Tracer tracer = new Tracer();
-tracer.setTraceOutExchanges(true);
-
-// we configure the default trace formatter where we can
-// specify which fields we want in the output
-DefaultTraceFormatter formatter = new DefaultTraceFormatter();
-formatter.setShowOutBody(true);
-formatter.setShowOutBodyType(true);
-
-// set to use our formatter
-tracer.setFormatter(formatter);
-
-getContext().addInterceptStrategy(tracer);
-]]></script>
-</div></div> <p>or</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>Spring DSL</b></div><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<bean id="camelTracer"
class="org.apache.camel.processor.interceptor.Tracer">
- <property name="traceOutExchanges" value="true" />
-</bean>
-
-<bean id="traceFormatter"
class="org.apache.camel.processor.interceptor.DefaultTraceFormatter">
- <property name="showOutBody" value="true" />
- <property name="showOutBodyType" value="true" />
-</bean>
-]]></script>
-</div></div> <p>With these options the output will look like:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[INFO TraceInterceptor -
ID-mojo/59899-1225474989226/2-0 -> transform(body) , Pattern:InOnly ,
Headers:{to=James} , BodyType:String , Body:Hello London
+</plain-text-body><p>You can see this in action with the <a shape="rect"
class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringTraceTest.java">SpringTraceTest</a>
and its <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringTraceTest-context.xml">spring.xml
file</a></p><p>Another option is to just include a spring XML which defines
the Tracer bean such as the <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-spring/src/main/resources/META-INF/services/org/apache/camel/spring/trace.xml">one
that is automatically included if you run the Main with -t above</a>.</p><h3
id="Tracer-ConfiguringinSpringXML">Configuring in Spring XML</h3><p>You can
configure the tracer as a Spring bean. Just add a bean with the bean class <stro
ng><code>org.apache.camel.processor.interceptor.Tracer</code></strong> and
Camel will use it as the
tracer.<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/tracerConfigurationTest.xml}</plain-text-body> </p><p>You
can configure the formatting of tracer as a Spring bean. Just add a bean with
the <strong><code>id="traceFormatter"</code></strong> and Camel will
lookup this <strong><code>id</code></strong> and use the associated
formatter.</p><p>Example:<plain-text-body>{snippet:id=e1|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/traceFormatterTest.xml}</plain-text-body></p><h3
id="Tracer-EnableTracingofOUTMessages">Enable Tracing of <code>OUT</code>
Messages</h3><p>To trace the messages coming out of processing steps configure
the tracer as
follows:<plain-text-body>{snippet:id=tracingOutExchanges|title=Java
DSL|lang=java|ur
l=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorWithOutBodyTraceTest.java}</plain-text-body> </p><p>or<plain-text-body>{snippet:id=tracingOutExchanges|title=Spring
DSL|lang=xml|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/traceInterceptorWithOutBodyTrace.xml}</plain-text-body> </p><p>With
these options the output will look like:</p><plain-text-body>INFO
TraceInterceptor - ID-mojo/59899-1225474989226/2-0 -> transform(body) ,
Pattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London
INFO TraceInterceptor - transform(body) -> ID-mojo/59899-1225474989226/2-0
, Pattern:InOnly , Headers:{to=James} , BodyType:String , Body:Hello London ,
OutBodyType:String , OutBody:Hello London
-]]></script>
-</div></div><h3 id="Tracer-UsingaCustomFormatter">Using a Custom
Formatter</h3><p>To create a custom formatter create a class that implements
the interface
<strong><code>org.apache.camel.processor.interceptor.TraceFormatter</code></strong>.</p><p>Example:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-// we create a tracer where we want to use our own formatter instead of the
default one
-Tracer tracer = new Tracer();
-
-// use our own formatter instead of the default one
-MyTraceFormatter formatter = new MyTraceFormatter();
-tracer.setFormatter(formatter);
-
-// and we must remeber to add the tracer to Camel
-getContext().addInterceptStrategy(tracer);
-]]></script>
-</div></div> <p>And here we have our custom logger that implements the
<strong><code>TraceFormatter</code></strong> interface where we can construct
the log message how we like:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-// here we have out own formatter where we can create the output we want for
trace logs
-// as this is a test we just create a simple string with * around the body
-class MyTraceFormatter implements TraceFormatter {
-
- public Object format(TraceInterceptor interceptor,
ProcessorDefinition<?> node, Exchange exchange) {
- return "***" + exchange.getIn().getBody(String.class) +
"***";
- }
-}
-]]></script>
-</div></div><h3
id="Tracer-UsingaDestinationforCustomProcessingandRouting">Using a Destination
for Custom Processing and Routing</h3><p>Tracer supports custom processing of
trace events. This can be used to route a trace event to a <a shape="rect"
href="jpa.html">JPA</a> endpoint for persistence in a database.</p><p>This
works by Camel creates a new <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventMessage.html">TraceEventMessage</a>
containing:</p><ul class="alternate"><li>snapshot of the original traced
Exchange as a immutable <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventMessage.html">TraceEventMessage</a>
containing String values of the fields, when the interception occurred. This
ensures the fields contains the exact data at the given time of
interception.</li><li>the original
Exchange can in some implementations be accessed using
<strong><code>getTracedExchange()</code></strong> (though with JPA based tracer
you cannot get the original Exchange).</li></ul><div
class="confluence-information-macro confluence-information-macro-warning"><span
class="aui-icon aui-icon-small aui-iconfont-error
confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>Beware to access the original
Exchange to avoid causing any side effects or alter its state. Prefer to access
the information from <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventMessage.html">TraceEventMessage</a></p></div></div><p>Camel
routes the <strong><code>TraceEventMessage</code></strong> synchronously
from the point of interception. When its completed Camel will continue routing
the original Exchange.</p><p>The sample below demonstrates this feature, where
we route t
raced Exchanges to the <strong><code>direct:traced</code></strong>
route:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-// we create a tracer where we want to send TraveEvents to an endpoint
-// "direct:traced" where we can do some custom processing such as
storing
-// it in a file or a database
-Tracer tracer = new Tracer();
-tracer.setDestinationUri("direct:traced");
-// we disable regular trace logging in the log file. You can omit this and
-// have both.
-tracer.setLogLevel(LoggingLevel.OFF);
-// and we must remember to add the tracer to Camel
-getContext().addInterceptStrategy(tracer);
-]]></script>
-</div></div> <p> </p><p>Then we can configure a route for the traced
messages:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:traced")
+</plain-text-body><h3 id="Tracer-UsingaCustomFormatter">Using a Custom
Formatter</h3><p>To create a custom formatter create a class that implements
the interface
<strong><code>org.apache.camel.processor.interceptor.TraceFormatter</code></strong>.</p><p>Example:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceFormatterTest.java}</plain-text-body> </p><p>And
here we have our custom logger that implements the
<strong><code>TraceFormatter</code></strong> interface where we can construct
the log message how we
like:<plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceFormatterTest.java}</plain-text-body></p><h3
id="Tracer-UsingaDestinationforCustomProcessingandRouting">Using a Destination
for Custom Processing and Routing</h3><p>Tracer supports custom processing of
trace events. This can be used to route a trace event to a <a shape="
rect" href="jpa.html">JPA</a> endpoint for persistence in a
database.</p><p>This works by Camel creates a new <a shape="rect"
class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventMessage.html">TraceEventMessage</a>
containing:</p><ul class="alternate"><li>snapshot of the original traced
Exchange as a immutable <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventMessage.html">TraceEventMessage</a>
containing String values of the fields, when the interception occurred. This
ensures the fields contains the exact data at the given time of
interception.</li><li>the original Exchange can in some implementations be
accessed using <strong><code>getTracedExchange()</code></strong> (though with
JPA based tracer you cannot get the original
Exchange).</li></ul><rich-text-body><p>Beware to access the original Exchange t
o avoid causing any side effects or alter its state. Prefer to access the
information from <a shape="rect" class="external-link"
href="http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/processor/interceptor/TraceEventMessage.html">TraceEventMessage</a></p></rich-text-body><p>Camel
routes the <strong><code>TraceEventMessage</code></strong> synchronously
from the point of interception. When its completed Camel will continue routing
the original Exchange.</p><p>The sample below demonstrates this feature, where
we route traced Exchanges to the <strong><code>direct:traced</code></strong>
route:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceInterceptorDestinationTest.java}</plain-text-body> </p><p> </p><p>Then
we can configure a route for the traced
messages:</p><plain-text-body>from("direct:traced")
.process(new MyTraceMessageProcessor())
- .to("file://myapp/logs/trace);
-]]></script>
-</div></div><p>And our processor where we can process the
<strong><code>TraceEventMessage</code></strong>. Here we want to create a CSV
format of the trace event to be stored as a file. We do this by constructing
the CSV String and the replace the <strong><code>IN</code></strong> body
with our String instead of the
<strong><code>TraceEventMessage</code></strong>.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-class MyTraceMessageProcessor implements Processor {
-
- public void process(Exchange exchange) throws Exception {
- // here we can transform the message how we like want it
- TraceEventMessage msg =
exchange.getIn().getBody(DefaultTraceEventMessage.class);
-
- // we want to store it as a CSV with from;to;exchangeId;body
- String s = msg.getFromEndpointUri() + ";" + msg.getToNode()
+ ";" + msg.getExchangeId() + ";" + msg.getBody();
-
- // so we replace the IN body with our CSV string
- exchange.getIn().setBody(s);
- }
-}
-]]></script>
-</div></div><h3 id="Tracer-UsingasaDatastoreforTraceMessages">Using <a
shape="rect" href="jpa.html">JPA</a> as a Datastore for Trace
Messages</h3><p>See <a shape="rect" href="tracer-example.html">Tracer
Example</a> for complete documentation and how to use this feature.</p><h3
id="Tracer-TracedRoutePathDuringRuntime">Traced Route Path During
Runtime</h3><p><a shape="rect" href="tracer.html">Tracer</a> also traces the
actual route path taken during runtime. Camel will store the route path taken
on the UnitOfWork when <a shape="rect" href="tracer.html">Tracer</a> is
enabled. The example below demonstrates how we can use that for error handling
where we can determine at which node in the route graph the error
triggered.</p><p>First we define our route:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- public void configure() throws Exception {
-
errorHandler(deadLetterChannel("mock:error").redeliveryDelay(0).maximumRedeliveries(3));
-
- // must enable tracer to trace the route path taken during runtime
- context.setTracing(true);
-
- // let our my error processor handle all exceptions
- onException(Exception.class).handled(true).process(new
MyErrorProcessor());
-
- // our route where an exception can be thrown from either foo or
bar bean
- // so we have enable tracing so we can check it at runtime to get
the actual
- // node path taken
-
from("direct:start").to("bean:foo").to("bean:bar");
- }
- };
-}
-]]></script>
-</div></div>And then our custom error processor where we can handle the
exception and figure out at which node the exception occurred.<div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-private static class MyErrorProcessor implements Processor {
- public void process(Exchange exchange) throws Exception {
- TracedRouteNodes traced =
exchange.getUnitOfWork().getTracedRouteNodes();
-
- // get the list of intercepted nodes
- List<RouteNode> list = traced.getNodes();
- // get the 3rd last as its the bean
- Processor last = list.get(list.size() - 3).getProcessor();
-
- // wrapped by JMX
- if (last instanceof InstrumentationProcessor) {
- InstrumentationProcessor ip = (InstrumentationProcessor) last;
- last = ip.getProcessor();
- }
-
- // set error message
- exchange.getOut().setFault(true);
- exchange.getOut().setBody("Failed at: " + last.toString());
- }
-
- public String toString() {
- return "MyErrorProcessor";
- }
-}
-]]></script>
-</div></div><h3 id="Tracer-SeeAlso">See Also</h3><ul class="alternate"><li><a
shape="rect" href="tracer-example.html">Tracer Example</a></li><li><a
shape="rect" href="debugger.html">Debugger</a></li><li><a shape="rect"
href="delay-interceptor.html">Delay Interceptor</a></li><li><a shape="rect"
href="log.html">Log</a></li></ul></div>
+ .to("file://myapp/logs/trace);
+</plain-text-body><p>And our processor where we can process the
<strong><code>TraceEventMessage</code></strong>. Here we want to create a CSV
format of the trace event to be stored as a file. We do this by constructing
the CSV String and the replace the <strong><code>IN</code></strong> body
with our String instead of the
<strong><code>TraceEventMessage</code></strong>.<plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/TraceInterceptorDestinationTest.java}</plain-text-body></p><h3
id="Tracer-UsingasaDatastoreforTraceMessages">Using <a shape="rect"
href="jpa.html">JPA</a> as a Datastore for Trace Messages</h3><p>See <a
shape="rect" href="tracer-example.html">Tracer Example</a> for complete
documentation and how to use this feature.</p><h3
id="Tracer-TracedRoutePathDuringRuntime">Traced Route Path During
Runtime</h3><p><a shape="rect" href="tracer.html">Tracer</a> also traces the
actual route path taken during
runtime. Camel will store the route path taken on the UnitOfWork when <a
shape="rect" href="tracer.html">Tracer</a> is enabled. The example below
demonstrates how we can use that for error handling where we can determine at
which node in the route graph the error triggered.</p><p>First we define our
route:<plain-text-body>{snippet:id=e1|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java}</plain-text-body>And
then our custom error processor where we can handle the exception and figure
out at which node the exception
occurred.<plain-text-body>{snippet:id=e2|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceableUnitOfWorkTest.java}</plain-text-body></p><h3
id="Tracer-SeeAlso">See Also</h3><ul class="alternate"><li><a shape="rect"
href="tracer-example.html">Tracer Example</a></li><li><a shape="rect"
href="debugger.html">Debugger</a></li><li><a shape="rect"
href="delay-interceptor.html">Delay Interce
ptor</a></li><li><a shape="rect" href="log.html">Log</a></li></ul></div>
</td>
<td valign="top">
<div class="navigation">