camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Claus Ibsen (Confluence)" <conflue...@apache.org>
Subject [CONF] Apache Camel > LogEIP
Date Wed, 10 Jul 2013 10:15:00 GMT
<html>
<head>
    <base href="https://cwiki.apache.org/confluence">
            <link rel="stylesheet" href="/confluence/s/en/2176/1/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/LogEIP">LogEIP</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" >{info}  <br> <br></td></tr>
            <tr><td class="diff-added-lines" style="background-color: #dfd;">{tip:title=Logging
message body with streamed messages} <br>If the message body is stream based, then logging
the message body, may cause the message body to be _empty_ afterwards. See this [FAQ|Why is
my message body empty?]. For streamed messages you can use [Stream Caching] to allow logging
the message body and be able to read the message body afterwards again. <br>{tip} <br></td></tr>
            <tr><td class="diff-unchanged" > <br>The log DSL have overloaded
methods to set the logging level and/or name as well. <br></td></tr>
            <tr><td class="diff-snipped" >...<br></td></tr>
    
            </table>
    </div>                            <h4>Full Content</h4>
                    <div class="notificationGreySide">
        <h2><a name="LogEIP-Log"></a>Log</h2>

<p>How can I log processing a <a href="/confluence/display/CAMEL/Message" title="Message">Message</a>?</p>

<p>Camel provides many ways to log processing a message. Here is just some examples:</p>
<ul class="alternate" type="square">
	<li>You can use the <a href="/confluence/display/CAMEL/Log" title="Log">Log</a>
component which logs the Message content.</li>
	<li>You can use the <a href="/confluence/display/CAMEL/Tracer" title="Tracer">Tracer</a>
which trace logs message flow.</li>
	<li>You can also use a <a href="/confluence/display/CAMEL/Processor" title="Processor">Processor</a>
or <a href="/confluence/display/CAMEL/Bean" title="Bean">Bean</a> and log from
Java code.</li>
	<li>You can use the <tt>log</tt> DSL.</li>
</ul>


<h3><a name="LogEIP-UsinglogDSL"></a>Using log DSL</h3>

<p>And in <b>Camel 2.2</b> you can use the <tt>log</tt> DSL
which allows you to use <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a>
language to construct a dynamic message which gets logged.<br/>
For example you can do</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("direct:start").log("Processing ${id}").to("bean:foo");
</pre>
</div></div>

<p>Which will construct a String message at runtime using the <a href="/confluence/display/CAMEL/Simple"
title="Simple">Simple</a> language. The log message will by logged at <tt>INFO</tt>
level using the route id as the log name. By default a route is named <tt>route-1</tt>,
<tt>route-2</tt> etc. But you can use the <tt>routeId("myCoolRoute")</tt>
to set a route name of choice.</p>

<div class='panelMacro'><table class='infoMacro'><colgroup><col width='24'><col></colgroup><tr><td
valign='top'><img src="/confluence/images/icons/emoticons/information.gif" width="16"
height="16" align="absmiddle" alt="" border="0"></td><td><b>Difference
between log in the DSL and <a href="/confluence/display/CAMEL/Log" title="Log">Log</a>
component</b><br />The <tt>log</tt> DSL is much lighter and meant
for logging human logs such as <tt>Starting to do ...</tt> etc. It can only log
a message based on the <a href="/confluence/display/CAMEL/Simple" title="Simple">Simple</a>
language. On the other hand <a href="/confluence/display/CAMEL/Log" title="Log">Log</a>
component is a full fledged component which involves using endpoints and etc. The <a href="/confluence/display/CAMEL/Log"
title="Log">Log</a> component is meant for logging the Message itself and you have
many URI options to control what you would like to be logged.</td></tr></table></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 message body
with streamed messages</b><br />If the message body is stream based, then logging
the message body, may cause the message body to be <em>empty</em> afterwards.
See this <a href="/confluence/pages/viewpage.action?pageId=30743508" title="Why is my message
body empty?">FAQ</a>. For streamed messages you can use <a href="/confluence/display/CAMEL/Stream+caching"
title="Stream caching">Stream caching</a> to allow logging the message body and be
able to read the message body afterwards again.</td></tr></table></div>

<p>The log DSL have overloaded methods to set the logging level and/or name as well.</p>

<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("direct:start").log(LoggingLevel.DEBUG, "Processing ${id}").to("bean:foo");
</pre>
</div></div>

<p>For example you can use this to log the file name being processed if you consume
files.</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: java; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
from("file://target/files").log(LoggingLevel.DEBUG, "Processing file ${file:name}").to("bean:foo");
</pre>
</div></div>

<h4><a name="LogEIP-UsinglogDSLfromSpring"></a>Using log DSL from Spring</h4>
<p>In Spring DSL its also easy to use log DSL as shown below:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
        &lt;route id="foo"&gt;
            &lt;from uri="direct:foo"/&gt;
            &lt;log message="Got ${body}"/&gt;
            &lt;to uri="mock:foo"/&gt;
        &lt;/route&gt;
</pre>
</div></div>

<p>The log tag has attributes to set the <tt>message</tt>, <tt>loggingLevel</tt>
and <tt>logName</tt>. For example:</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
        &lt;route id="baz"&gt;
            &lt;from uri="direct:baz"/&gt;
            &lt;log message="Me Got ${body}" loggingLevel="FATAL" logName="cool"/&gt;
            &lt;to uri="mock:baz"/&gt;
        &lt;/route&gt;
</pre>
</div></div>

<h4><a name="LogEIP-Usingslf4jMarker"></a>Using slf4j Marker</h4>
<p><b>Available as of Camel 2.9</b></p>

<p>You can specify a marker name in the DSL</p>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Default; brush: xml; gutter: false" style="font-size:12px; font-family:
ConfluenceInstalledFont,monospace;">
        &lt;route id="baz"&gt;
            &lt;from uri="direct:baz"/&gt;
            &lt;log message="Me Got ${body}" loggingLevel="FATAL" logName="cool" marker="myMarker"/&gt;
            &lt;to uri="mock:baz"/&gt;
        &lt;/route&gt;
</pre>
</div></div>


<h4><a name="LogEIP-UsingThisPattern"></a>Using This Pattern</h4>

<p>If you would like to use this EIP Pattern then please read the <a href="/confluence/display/CAMEL/Getting+Started"
title="Getting Started">Getting Started</a>, you may also find the <a href="/confluence/display/CAMEL/Architecture"
title="Architecture">Architecture</a> useful particularly the description of <a
href="/confluence/display/CAMEL/Endpoint" title="Endpoint">Endpoint</a> and <a
href="/confluence/display/CAMEL/URIs" title="URIs">URIs</a>. Then you could try out
some of the <a href="/confluence/display/CAMEL/Examples" title="Examples">Examples</a>
first before trying this pattern out.</p>
    </div>
        <div id="commentsSection" class="wiki-content pageSection">
        <div style="float: right;" class="grey">
                        <a href="https://cwiki.apache.org/confluence/users/removespacenotification.action?spaceKey=CAMEL">Stop
watching space</a>
            <span style="padding: 0px 5px;">|</span>
                <a href="https://cwiki.apache.org/confluence/users/editmyemailsettings.action">Change
email notification preferences</a>
</div>
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/LogEIP">View Online</a>
        |
        <a href="https://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=9373998&revisedVersion=8&originalVersion=7">View
Changes</a>
                |
        <a href="https://cwiki.apache.org/confluence/display/CAMEL/LogEIP?showComments=true&amp;showCommentArea=true#addcomment">Add
Comment</a>
            </div>
</div>
</div>
</div>
</div>
</body>
</html>

Mime
View raw message