1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Does Boost.Log support logging at process initialization and termination?</title> 5<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../index.html" title="Chapter 1. Boost.Log v2"> 8<link rel="up" href="../rationale.html" title="Rationale and FAQ"> 9<link rel="prev" href="fork_support.html" title="Does Boost.Log support process forking?"> 10<link rel="next" href="why_crash_on_term.html" title="Why my application crashes on process termination when file sinks are used?"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td></tr></table> 14<hr> 15<div class="spirit-nav"> 16<a accesskey="p" href="fork_support.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_crash_on_term.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 17</div> 18<div class="section"> 19<div class="titlepage"><div><div><h3 class="title"> 20<a name="log.rationale.init_term_support"></a><a class="link" href="init_term_support.html" title="Does Boost.Log support logging at process initialization and termination?">Does Boost.Log support 21 logging at process initialization and termination?</a> 22</h3></div></div></div> 23<p> 24 It should be fine to use logging during the application initialization (i.e. 25 before <code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code> 26 starts). But there are a number of known problems with Boost.Log that prevent 27 it from being used at process termination (i.e. after the <code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code> function returns), so the official answer 28 to the second part is no. It may work though, in some very restricted setups, 29 if several rules are followed: 30 </p> 31<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 32<li class="listitem"> 33 Do not create any objects at process termination, including loggers, 34 attributes or sinks. Try to create and cache the required objects as 35 soon as the application starts (maybe even before <code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code> starts). 36 </li> 37<li class="listitem"> 38 Do not use global loggers at process termination. 39 </li> 40<li class="listitem"> 41 Do not call <code class="computeroutput"><span class="identifier">logging</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">get</span><span class="special">()</span></code> 42 at process termination. Get that pointer as early as possible and keep 43 it until the process terminates. 44 </li> 45<li class="listitem"> 46 Do not use named scopes in termination code. 47 </li> 48</ul></div> 49<p> 50 These rules don't guarantee that the library will work in termination context 51 but they may help to avoid problems. The library will get improved to support 52 this use case better. 53 </p> 54</div> 55<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 56<td align="left"></td> 57<td align="right"><div class="copyright-footer">Copyright © 2007-2019 Andrey Semashev<p> 58 Distributed under the Boost Software License, Version 1.0. (See accompanying 59 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>). 60 </p> 61</div></td> 62</tr></table> 63<hr> 64<div class="spirit-nav"> 65<a accesskey="p" href="fork_support.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_crash_on_term.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 66</div> 67</body> 68</html> 69