1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Log level configuration</title> 5<link rel="stylesheet" href="../../../boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../../index.html" title="Boost.Test"> 8<link rel="up" href="../logging_api.html" title="Logging API"> 9<link rel="prev" href="log_ct_output_stream_redirection.html" title="Log output stream redirection"> 10<link rel="next" href="log_ct_log_format.html" title="Predefined log format selection"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td> 15<td align="center"><a href="../../../../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="log_ct_output_stream_redirection.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../logging_api.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="log_ct_log_format.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h4 class="title"> 27<a name="boost_test.test_output.logging_api.log_ct_log_level"></a><a name="ref_log_level_explanations"></a><a class="link" href="log_ct_log_level.html" title="Log level configuration">Log 28 level configuration</a> 29</h4></div></div></div> 30<p> 31 If you need to enforce specific log level from within your test module 32 use the following interface: 33 </p> 34<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">::</span><span class="identifier">unit_test_log</span><span class="special">.</span><span class="identifier">set_threshold_level</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">::</span><span class="identifier">log_level</span> <span class="special">);</span> 35</pre> 36<p> 37 or for a specific logger: 38 </p> 39<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">::</span><span class="identifier">unit_test_log</span><span class="special">.</span><span class="identifier">set_threshold_level</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">::</span><span class="identifier">output_format</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">::</span><span class="identifier">log_level</span> <span class="special">);</span> 40</pre> 41<div class="tip"><table border="0" summary="Tip"> 42<tr> 43<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../../doc/src/images/tip.png"></td> 44<th align="left">Tip</th> 45</tr> 46<tr><td align="left" valign="top"><p> 47 See <code class="computeroutput"><a class="link" href="../../../boost/unit_test/unit_test_log_t.html#idm45267286534144-bb">boost::unit_test::unit_test_log_t::set_threshold_level</a></code> 48 and <code class="computeroutput"><a class="link" href="../../../header/boost/test/detail/global_typedef_hpp.html#boost.unit_test.output_format">boost::unit_test::output_format</a></code> 49 for more details 50 </p></td></tr> 51</table></div> 52<p> 53 In regular circumstances you shouldn't use this interface, since you not 54 only override default log level, but also the one supplied at test execution 55 time. Prefer to use runtime parameters <a class="link" href="../../utf_reference/rt_param_reference/log_level.html" title="log_level"><code class="computeroutput"><span class="special">--</span><span class="identifier">log_level</span></code></a> 56 or <a class="link" href="../../utf_reference/rt_param_reference/logger.html" title="logger"><code class="computeroutput"><span class="special">--</span><span class="identifier">logger</span></code></a> 57 for log level selection. 58 </p> 59<h6> 60<a name="boost_test.test_output.logging_api.log_ct_log_level.h0"></a> 61 <span class="phrase"><a name="boost_test.test_output.logging_api.log_ct_log_level.example_descr"></a></span><a class="link" href="log_ct_log_level.html#boost_test.test_output.logging_api.log_ct_log_level.example_descr">Example: 62 Compile-time log level configuration</a> 63 </h6> 64<div class="informaltable"><table class="table"> 65<colgroup><col></colgroup> 66<thead><tr><th> 67 <p> 68 Code 69 </p> 70 </th></tr></thead> 71<tbody><tr><td> 72<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">example</span> 73<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 74<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">unit_test_parameters</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 75<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">unit_test</span><span class="special">;</span> 76 77<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_case0</span> <span class="special">)</span> 78<span class="special">{</span> 79 <span class="keyword">if</span><span class="special">(</span> <span class="identifier">runtime_config</span><span class="special">::</span><span class="identifier">get</span><span class="special"><</span><span class="identifier">log_level</span><span class="special">>(</span> <span class="identifier">runtime_config</span><span class="special">::</span><span class="identifier">btrt_log_level</span> <span class="special">)</span> <span class="special"><</span> <span class="identifier">log_warnings</span> <span class="special">)</span> 80 <span class="identifier">unit_test_log</span><span class="special">.</span><span class="identifier">set_threshold_level</span><span class="special">(</span> <span class="identifier">log_warnings</span> <span class="special">);</span> 81 82 <span class="identifier">BOOST_WARN</span><span class="special">(</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="keyword">int</span><span class="special">)</span> <span class="special">></span> <span class="number">4</span> <span class="special">);</span> 83<span class="special">}</span> 84</pre> 85 </td></tr></tbody> 86</table></div> 87<div class="informaltable"><table class="table"> 88<colgroup><col></colgroup> 89<thead><tr><th> 90 <p> 91 Output 92 </p> 93 </th></tr></thead> 94<tbody><tr><td> 95<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">></span> <span class="identifier">example</span> 96<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span> 97<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">13</span><span class="special">):</span> <span class="identifier">warning</span> <span class="identifier">in</span> <span class="string">"test_case0"</span><span class="special">:</span> <span class="identifier">condition</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="keyword">int</span><span class="special">)</span> <span class="special">></span> <span class="number">4</span> <span class="identifier">is</span> <span class="keyword">not</span> <span class="identifier">satisfied</span> 98 99<span class="special">***</span> <span class="identifier">No</span> <span class="identifier">errors</span> <span class="identifier">detected</span> 100</pre> 101 </td></tr></tbody> 102</table></div> 103</div> 104<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 105<td align="left"></td> 106<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p> 107 Distributed under the Boost Software License, Version 1.0. (See accompanying 108 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>) 109 </p> 110</div></td> 111</tr></table> 112<hr> 113<div class="spirit-nav"> 114<a accesskey="p" href="log_ct_output_stream_redirection.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../logging_api.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="log_ct_log_format.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a> 115</div> 116</body> 117</html> 118