blob: ac30ac80e0c54d382c42eda95d8498ffe5515f00 [file] [log] [blame]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Rationale and FAQ</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="../index.html" title="Chapter&#160;1.&#160;Boost.Log v2">
<link rel="prev" href="extension/settings.html" title="Extending library settings support">
<link rel="next" href="rationale/why_weak_scoped_attributes.html" title="Why scoped attributes don't override existing attributes?">
</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="extension/settings.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="rationale/why_weak_scoped_attributes.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="log.rationale"></a><a class="link" href="rationale.html" title="Rationale and FAQ">Rationale and FAQ</a>
</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="rationale.html#log.rationale.why_str_lit">Why string literals as scope
names?</a></span></dt>
<dt><span class="section"><a href="rationale/why_weak_scoped_attributes.html">Why scoped
attributes don't override existing attributes?</a></span></dt>
<dt><span class="section"><a href="rationale/why_weak_record_ordering.html">Why log records
are weakly ordered in a multithreaded application?</a></span></dt>
<dt><span class="section"><a href="rationale/why_attribute_manips_dont_affect_filters.html">Why
attributes set with stream manipulators do not participate in filtering?</a></span></dt>
<dt><span class="section"><a href="rationale/why_not_lazy_streaming.html">Why not using lazy
streaming?</a></span></dt>
<dt><span class="section"><a href="rationale/why_not_log4j.html">Why not using hierarchy
of loggers, like in log4j? Why not Boost.Log4j? Etc.</a></span></dt>
<dt><span class="section"><a href="rationale/fork_support.html">Does Boost.Log support process
forking?</a></span></dt>
<dt><span class="section"><a href="rationale/init_term_support.html">Does Boost.Log support
logging at process initialization and termination?</a></span></dt>
<dt><span class="section"><a href="rationale/why_crash_on_term.html">Why my application crashes
on process termination when file sinks are used?</a></span></dt>
<dt><span class="section"><a href="rationale/namespace_mangling.html">Why my application
fails to link with Boost.Log? What's the fuss about library namespaces?</a></span></dt>
<dt><span class="section"><a href="rationale/msvc_link_fails_lnk1123.html">Why MSVC 2010
fails to link the library with error LNK1123: failure during conversion to
COFF: file invalid or corrupt?</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="log.rationale.why_str_lit"></a><a class="link" href="rationale.html#log.rationale.why_str_lit" title="Why string literals as scope names?">Why string literals as scope
names?</a>
</h3></div></div></div>
<p>
One may wonder why not allow arbitrary strings to be used as named scope
names. The answer is simple: for performance and safety reasons. Named scope
support functionality has one significant difference from other attribute-related
features of the library. The scope stack is maintained even when no logging
is done, so if a function <code class="computeroutput"><span class="identifier">foo</span></code>
has a <code class="computeroutput"><span class="identifier">BOOST_LOG_FUNCTION</span><span class="special">()</span></code> statement in its body, it is always a slowdown.
Allowing the scope name to be an arbitrary string would make the slowdown
significantly greater because of the need to allocate memory and copy the
string (not to mention that there would be a need to previously format it,
which also takes its toll).
</p>
<p>
Dynamic memory allocation also introduces exception safety issues: the <code class="computeroutput"><span class="identifier">BOOST_LOG_FUNCTION</span><span class="special">()</span></code>
statement (and alikes) would become a potential source of exceptions. These
issues would complicate user's code if he wants to solve memory allocation
problems gracefully.
</p>
<p>
One possible alternative solution would be pooling pre-formatted and pre-allocated
scope names somewhere but this would surely degrade performance even more
and introduce the problem of detecting when to update or free pooled strings.
</p>
<p>
Therefore restricting to string literals seemed to be the optimal decision,
which reduced dynamic memory usage and provided enough flexibility for common
needs.
</p>
</div>
</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="extension/settings.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="rationale/why_weak_scoped_attributes.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>