blob: 6abd23451213378e4cd64965f2edd494f5190623 [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Why not using lazy streaming?</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../../index.html" title="Chapter&#160;1.&#160;Boost.Log v2">
<link rel="up" href="../rationale.html" title="Rationale and FAQ">
<link rel="prev" href="why_attribute_manips_dont_affect_filters.html" title="Why attributes set with stream manipulators do not participate in filtering?">
<link rel="next" href="why_not_log4j.html" title="Why not using hierarchy of loggers, like in log4j? Why not Boost.Log4j? Etc.">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="why_attribute_manips_dont_affect_filters.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rationale.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="why_not_log4j.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="log.rationale.why_not_lazy_streaming"></a><a class="link" href="why_not_lazy_streaming.html" title="Why not using lazy streaming?">Why not using lazy
streaming?</a>
</h3></div></div></div>
<p>
One of the possible library implementations would be using lazy expressions
to delay log record formatting. In essence, the expression:
</p>
<pre class="programlisting"><span class="identifier">logger</span> <span class="special">&lt;&lt;</span> <span class="string">"Hello, world!"</span><span class="special">;</span>
</pre>
<p>
would become a lambda-expression that is only invoked if the filtering is
successful. Although this approach has advantages, it must be noted that
lazy expression construction is not zero-cost in terms of performance, code
size and compile times. The following expression:
</p>
<pre class="programlisting"><span class="identifier">logger</span> <span class="special">&lt;&lt;</span> <span class="string">"Received packet from "</span> <span class="special">&lt;&lt;</span> <span class="identifier">ip</span> <span class="special">&lt;&lt;</span> <span class="string">" of "</span> <span class="special">&lt;&lt;</span> <span class="identifier">packet</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="string">" bytes"</span><span class="special">;</span>
</pre>
<p>
would generate a considerable amount of code (proportional to the number
of streaming operators) to be executed before filtering takes place. Another
drawback is that the <code class="computeroutput"><span class="identifier">packet</span><span class="special">.</span><span class="identifier">size</span><span class="special">()</span></code>
is always called, whether or not the record is actually written to the log.
In order to delay this call, yet more scaffolding is needed, possibly involving
<a href="http://www.boost.org/doc/libs/release/libs/bind/bind.html" target="_top">Boost.Bind</a>,
<a href="http://www.boost.org/doc/libs/release/doc/html/lambda.html" target="_top">Boost.Lambda</a>
or <a href="http://www.boost.org/doc/libs/release/libs/phoenix/doc/html/index.html" target="_top">Boost.Phoenix</a>.
This complication is not acceptable for such a basic use case, like this.
</p>
<p>
Although lazy streaming is not provided by the library out of the box, nothing
prevents developing it in a separate hierarchy of loggers. See the <a class="link" href="../extension/sources.html" title="Writing your own sources">Extending the library</a> section for
more information.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2007-2015 Andrey
Semashev<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>).
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="why_attribute_manips_dont_affect_filters.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../rationale.html"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="why_not_log4j.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>