unit_test_log.ipp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. // (C) Copyright Gennadiy Rozental 2001.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision$
  10. //
  11. // Description : implemets Unit Test Log
  12. // ***************************************************************************
  13. #ifndef BOOST_TEST_UNIT_TEST_LOG_IPP_012205GER
  14. #define BOOST_TEST_UNIT_TEST_LOG_IPP_012205GER
  15. // Boost.Test
  16. #include <boost/test/unit_test_log.hpp>
  17. #include <boost/test/unit_test_log_formatter.hpp>
  18. #include <boost/test/execution_monitor.hpp>
  19. #include <boost/test/framework.hpp>
  20. #include <boost/test/unit_test_parameters.hpp>
  21. #include <boost/test/utils/basic_cstring/compare.hpp>
  22. #include <boost/test/utils/foreach.hpp>
  23. #include <boost/test/output/compiler_log_formatter.hpp>
  24. #include <boost/test/output/xml_log_formatter.hpp>
  25. #include <boost/test/output/junit_log_formatter.hpp>
  26. // Boost
  27. #include <boost/shared_ptr.hpp>
  28. #include <boost/io/ios_state.hpp>
  29. typedef ::boost::io::ios_base_all_saver io_saver_type;
  30. #include <boost/test/detail/suppress_warnings.hpp>
  31. //____________________________________________________________________________//
  32. namespace boost {
  33. namespace unit_test {
  34. // ************************************************************************** //
  35. // ************** entry_value_collector ************** //
  36. // ************************************************************************** //
  37. namespace ut_detail {
  38. entry_value_collector const&
  39. entry_value_collector::operator<<( lazy_ostream const& v ) const
  40. {
  41. unit_test_log << v;
  42. return *this;
  43. }
  44. //____________________________________________________________________________//
  45. entry_value_collector const&
  46. entry_value_collector::operator<<( const_string v ) const
  47. {
  48. unit_test_log << v;
  49. return *this;
  50. }
  51. //____________________________________________________________________________//
  52. entry_value_collector::~entry_value_collector()
  53. {
  54. if( m_last )
  55. unit_test_log << log::end();
  56. }
  57. //____________________________________________________________________________//
  58. } // namespace ut_detail
  59. // ************************************************************************** //
  60. // ************** unit_test_log ************** //
  61. // ************************************************************************** //
  62. namespace {
  63. // log data
  64. struct unit_test_log_data_helper_impl {
  65. typedef boost::shared_ptr<unit_test_log_formatter> formatter_ptr;
  66. typedef boost::shared_ptr<io_saver_type> saver_ptr;
  67. bool m_enabled;
  68. output_format m_format;
  69. std::ostream* m_stream;
  70. saver_ptr m_stream_state_saver;
  71. formatter_ptr m_log_formatter;
  72. bool m_entry_in_progress;
  73. unit_test_log_data_helper_impl(unit_test_log_formatter* p_log_formatter, output_format format, bool enabled = false)
  74. : m_enabled( enabled )
  75. , m_format( format )
  76. , m_stream( &std::cout )
  77. , m_stream_state_saver( new io_saver_type( std::cout ) )
  78. , m_log_formatter()
  79. , m_entry_in_progress( false )
  80. {
  81. m_log_formatter.reset(p_log_formatter);
  82. m_log_formatter->set_log_level(log_all_errors);
  83. }
  84. // helper functions
  85. std::ostream& stream()
  86. {
  87. return *m_stream;
  88. }
  89. log_level get_log_level() const
  90. {
  91. return m_log_formatter->get_log_level();
  92. }
  93. };
  94. struct unit_test_log_impl {
  95. // Constructor
  96. unit_test_log_impl()
  97. {
  98. m_log_formatter_data.push_back( unit_test_log_data_helper_impl(new output::compiler_log_formatter, OF_CLF, true) ); // only this one is active by default,
  99. m_log_formatter_data.push_back( unit_test_log_data_helper_impl(new output::xml_log_formatter, OF_XML, false) );
  100. m_log_formatter_data.push_back( unit_test_log_data_helper_impl(new output::junit_log_formatter, OF_JUNIT, false) );
  101. }
  102. typedef std::vector<unit_test_log_data_helper_impl> v_formatter_data_t;
  103. v_formatter_data_t m_log_formatter_data;
  104. // entry data
  105. log_entry_data m_entry_data;
  106. bool has_entry_in_progress() const {
  107. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl const&, current_logger_data, m_log_formatter_data ) {
  108. if( current_logger_data.m_entry_in_progress )
  109. return true;
  110. }
  111. return false;
  112. }
  113. // check point data
  114. log_checkpoint_data m_checkpoint_data;
  115. void set_checkpoint( const_string file, std::size_t line_num, const_string msg )
  116. {
  117. assign_op( m_checkpoint_data.m_message, msg, 0 );
  118. m_checkpoint_data.m_file_name = file;
  119. m_checkpoint_data.m_line_num = line_num;
  120. }
  121. };
  122. unit_test_log_impl& s_log_impl() { static unit_test_log_impl the_inst; return the_inst; }
  123. } // local namespace
  124. //____________________________________________________________________________//
  125. BOOST_TEST_SINGLETON_CONS_IMPL( unit_test_log_t )
  126. //____________________________________________________________________________//
  127. void
  128. unit_test_log_t::test_start( counter_t test_cases_amount )
  129. {
  130. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  131. if( !current_logger_data.m_enabled || current_logger_data.get_log_level() == log_nothing )
  132. continue;
  133. current_logger_data.m_log_formatter->log_start( current_logger_data.stream(), test_cases_amount );
  134. current_logger_data.m_log_formatter->log_build_info(
  135. current_logger_data.stream(),
  136. runtime_config::get<bool>( runtime_config::btrt_build_info ));
  137. //current_logger_data.stream().flush();
  138. current_logger_data.m_entry_in_progress = false;
  139. }
  140. }
  141. //____________________________________________________________________________//
  142. void
  143. unit_test_log_t::test_finish()
  144. {
  145. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  146. if( !current_logger_data.m_enabled || current_logger_data.get_log_level() == log_nothing )
  147. continue;
  148. current_logger_data.m_log_formatter->log_finish( current_logger_data.stream() );
  149. current_logger_data.stream().flush();
  150. }
  151. }
  152. //____________________________________________________________________________//
  153. void
  154. unit_test_log_t::test_aborted()
  155. {
  156. BOOST_TEST_LOG_ENTRY( log_messages ) << "Test is aborted";
  157. }
  158. //____________________________________________________________________________//
  159. void
  160. unit_test_log_t::test_unit_start( test_unit const& tu )
  161. {
  162. if( s_log_impl().has_entry_in_progress() )
  163. *this << log::end();
  164. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  165. if( !current_logger_data.m_enabled || current_logger_data.get_log_level() > log_test_units )
  166. continue;
  167. current_logger_data.m_log_formatter->test_unit_start( current_logger_data.stream(), tu );
  168. }
  169. }
  170. //____________________________________________________________________________//
  171. void
  172. unit_test_log_t::test_unit_finish( test_unit const& tu, unsigned long elapsed )
  173. {
  174. s_log_impl().m_checkpoint_data.clear();
  175. if( s_log_impl().has_entry_in_progress() )
  176. *this << log::end();
  177. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  178. if( !current_logger_data.m_enabled || current_logger_data.get_log_level() > log_test_units )
  179. continue;
  180. current_logger_data.m_log_formatter->test_unit_finish( current_logger_data.stream(), tu, elapsed );
  181. }
  182. }
  183. //____________________________________________________________________________//
  184. void
  185. unit_test_log_t::test_unit_skipped( test_unit const& tu, const_string reason )
  186. {
  187. if( s_log_impl().has_entry_in_progress() )
  188. *this << log::end();
  189. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  190. if( !current_logger_data.m_enabled || current_logger_data.get_log_level() > log_test_units )
  191. continue;
  192. current_logger_data.m_log_formatter->test_unit_skipped( current_logger_data.stream(), tu, reason );
  193. }
  194. }
  195. void
  196. unit_test_log_t::test_unit_aborted( test_unit const& tu )
  197. {
  198. if( s_log_impl().has_entry_in_progress() )
  199. *this << log::end();
  200. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  201. if( !current_logger_data.m_enabled || current_logger_data.get_log_level() > log_test_units )
  202. continue;
  203. current_logger_data.m_log_formatter->test_unit_aborted(current_logger_data.stream(), tu );
  204. }
  205. }
  206. void
  207. unit_test_log_t::test_unit_timed_out( test_unit const& tu )
  208. {
  209. if( s_log_impl().has_entry_in_progress() )
  210. *this << log::end();
  211. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  212. if( !current_logger_data.m_enabled || current_logger_data.get_log_level() > log_test_units )
  213. continue;
  214. current_logger_data.m_log_formatter->test_unit_timed_out(current_logger_data.stream(), tu );
  215. }
  216. }
  217. //____________________________________________________________________________//
  218. void
  219. unit_test_log_t::exception_caught( execution_exception const& ex )
  220. {
  221. log_level l =
  222. ex.code() <= execution_exception::cpp_exception_error ? log_cpp_exception_errors :
  223. (ex.code() <= execution_exception::timeout_error ? log_system_errors
  224. : log_fatal_errors );
  225. if( s_log_impl().has_entry_in_progress() )
  226. *this << log::end();
  227. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  228. if( current_logger_data.m_enabled && l >= current_logger_data.get_log_level() ) {
  229. current_logger_data.m_log_formatter->log_exception_start( current_logger_data.stream(), s_log_impl().m_checkpoint_data, ex );
  230. log_entry_context( l );
  231. current_logger_data.m_log_formatter->log_exception_finish( current_logger_data.stream() );
  232. }
  233. }
  234. clear_entry_context();
  235. }
  236. //____________________________________________________________________________//
  237. void
  238. unit_test_log_t::set_checkpoint( const_string file, std::size_t line_num, const_string msg )
  239. {
  240. s_log_impl().set_checkpoint( file, line_num, msg );
  241. }
  242. //____________________________________________________________________________//
  243. char
  244. set_unix_slash( char in )
  245. {
  246. return in == '\\' ? '/' : in;
  247. }
  248. unit_test_log_t&
  249. unit_test_log_t::operator<<( log::begin const& b )
  250. {
  251. if( s_log_impl().has_entry_in_progress() )
  252. *this << log::end();
  253. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  254. if( current_logger_data.m_enabled ) {
  255. current_logger_data.m_stream_state_saver->restore();
  256. }
  257. }
  258. s_log_impl().m_entry_data.clear();
  259. assign_op( s_log_impl().m_entry_data.m_file_name, b.m_file_name, 0 );
  260. // normalize file name
  261. std::transform( s_log_impl().m_entry_data.m_file_name.begin(), s_log_impl().m_entry_data.m_file_name.end(),
  262. s_log_impl().m_entry_data.m_file_name.begin(),
  263. &set_unix_slash );
  264. s_log_impl().m_entry_data.m_line_num = b.m_line_num;
  265. return *this;
  266. }
  267. //____________________________________________________________________________//
  268. unit_test_log_t&
  269. unit_test_log_t::operator<<( log::end const& )
  270. {
  271. if( s_log_impl().has_entry_in_progress() ) {
  272. log_entry_context( s_log_impl().m_entry_data.m_level );
  273. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  274. if( current_logger_data.m_enabled && current_logger_data.m_entry_in_progress ) {
  275. current_logger_data.m_log_formatter->log_entry_finish( current_logger_data.stream() );
  276. }
  277. current_logger_data.m_entry_in_progress = false;
  278. }
  279. }
  280. clear_entry_context();
  281. return *this;
  282. }
  283. //____________________________________________________________________________//
  284. unit_test_log_t&
  285. unit_test_log_t::operator<<( log_level l )
  286. {
  287. s_log_impl().m_entry_data.m_level = l;
  288. return *this;
  289. }
  290. //____________________________________________________________________________//
  291. ut_detail::entry_value_collector
  292. unit_test_log_t::operator()( log_level l )
  293. {
  294. *this << l;
  295. return ut_detail::entry_value_collector();
  296. }
  297. //____________________________________________________________________________//
  298. bool
  299. unit_test_log_t::log_entry_start(output_format log_format)
  300. {
  301. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  302. if( current_logger_data.m_format != log_format )
  303. continue;
  304. if( current_logger_data.m_entry_in_progress )
  305. return true;
  306. if( !current_logger_data.m_enabled )
  307. return false;
  308. switch( s_log_impl().m_entry_data.m_level ) {
  309. case log_successful_tests:
  310. current_logger_data.m_log_formatter->log_entry_start( current_logger_data.stream(), s_log_impl().m_entry_data,
  311. unit_test_log_formatter::BOOST_UTL_ET_INFO );
  312. break;
  313. case log_messages:
  314. current_logger_data.m_log_formatter->log_entry_start( current_logger_data.stream(), s_log_impl().m_entry_data,
  315. unit_test_log_formatter::BOOST_UTL_ET_MESSAGE );
  316. break;
  317. case log_warnings:
  318. current_logger_data.m_log_formatter->log_entry_start( current_logger_data.stream(), s_log_impl().m_entry_data,
  319. unit_test_log_formatter::BOOST_UTL_ET_WARNING );
  320. break;
  321. case log_all_errors:
  322. case log_cpp_exception_errors:
  323. case log_system_errors:
  324. current_logger_data.m_log_formatter->log_entry_start( current_logger_data.stream(), s_log_impl().m_entry_data,
  325. unit_test_log_formatter::BOOST_UTL_ET_ERROR );
  326. break;
  327. case log_fatal_errors:
  328. current_logger_data.m_log_formatter->log_entry_start( current_logger_data.stream(), s_log_impl().m_entry_data,
  329. unit_test_log_formatter::BOOST_UTL_ET_FATAL_ERROR );
  330. break;
  331. case log_nothing:
  332. case log_test_units:
  333. case invalid_log_level:
  334. return false;
  335. }
  336. current_logger_data.m_entry_in_progress = true;
  337. return true;
  338. }
  339. return false;
  340. }
  341. //____________________________________________________________________________//
  342. unit_test_log_t&
  343. unit_test_log_t::operator<<( const_string value )
  344. {
  345. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  346. if( current_logger_data.m_enabled && s_log_impl().m_entry_data.m_level >= current_logger_data.get_log_level() && !value.empty() && log_entry_start(current_logger_data.m_format) )
  347. current_logger_data.m_log_formatter->log_entry_value( current_logger_data.stream(), value );
  348. }
  349. return *this;
  350. }
  351. //____________________________________________________________________________//
  352. unit_test_log_t&
  353. unit_test_log_t::operator<<( lazy_ostream const& value )
  354. {
  355. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  356. if( current_logger_data.m_enabled && s_log_impl().m_entry_data.m_level >= current_logger_data.get_log_level() && !value.empty() ) {
  357. if( log_entry_start(current_logger_data.m_format) ) {
  358. current_logger_data.m_log_formatter->log_entry_value( current_logger_data.stream(), value );
  359. }
  360. }
  361. }
  362. return *this;
  363. }
  364. //____________________________________________________________________________//
  365. void
  366. unit_test_log_t::log_entry_context( log_level l )
  367. {
  368. framework::context_generator const& context = framework::get_context();
  369. if( context.is_empty() )
  370. return;
  371. const_string frame;
  372. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  373. if( current_logger_data.m_enabled ) {
  374. current_logger_data.m_log_formatter->entry_context_start( current_logger_data.stream(), l );
  375. }
  376. }
  377. while( !(frame=context.next()).is_empty() )
  378. {
  379. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  380. if( current_logger_data.m_enabled ) {
  381. current_logger_data.m_log_formatter->log_entry_context( current_logger_data.stream(), l, frame );
  382. }
  383. }
  384. }
  385. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  386. if( current_logger_data.m_enabled ) {
  387. current_logger_data.m_log_formatter->entry_context_finish( current_logger_data.stream(), l );
  388. }
  389. }
  390. }
  391. //____________________________________________________________________________//
  392. void
  393. unit_test_log_t::clear_entry_context()
  394. {
  395. framework::clear_context();
  396. }
  397. //____________________________________________________________________________//
  398. void
  399. unit_test_log_t::set_stream( std::ostream& str )
  400. {
  401. if( s_log_impl().has_entry_in_progress() )
  402. return;
  403. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  404. current_logger_data.m_stream = &str;
  405. current_logger_data.m_stream_state_saver.reset( new io_saver_type( str ) );
  406. }
  407. }
  408. //____________________________________________________________________________//
  409. void
  410. unit_test_log_t::set_stream( output_format log_format, std::ostream& str )
  411. {
  412. if( s_log_impl().has_entry_in_progress() )
  413. return;
  414. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  415. if( current_logger_data.m_format == log_format) {
  416. current_logger_data.m_stream = &str;
  417. current_logger_data.m_stream_state_saver.reset( new io_saver_type( str ) );
  418. break;
  419. }
  420. }
  421. }
  422. std::ostream*
  423. unit_test_log_t::get_stream( output_format log_format ) const
  424. {
  425. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  426. if( current_logger_data.m_format == log_format) {
  427. return current_logger_data.m_stream;
  428. }
  429. }
  430. return 0;
  431. }
  432. //____________________________________________________________________________//
  433. void
  434. unit_test_log_t::set_threshold_level( log_level lev )
  435. {
  436. if( s_log_impl().has_entry_in_progress() || lev == invalid_log_level )
  437. return;
  438. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  439. current_logger_data.m_log_formatter->set_log_level( lev );
  440. }
  441. }
  442. //____________________________________________________________________________//
  443. void
  444. unit_test_log_t::set_threshold_level( output_format log_format, log_level lev )
  445. {
  446. if( s_log_impl().has_entry_in_progress() || lev == invalid_log_level )
  447. return;
  448. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  449. if( current_logger_data.m_format == log_format) {
  450. current_logger_data.m_log_formatter->set_log_level( lev );
  451. break;
  452. }
  453. }
  454. }
  455. //____________________________________________________________________________//
  456. void
  457. unit_test_log_t::set_format( output_format log_format )
  458. {
  459. if( s_log_impl().has_entry_in_progress() )
  460. return;
  461. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  462. current_logger_data.m_enabled = current_logger_data.m_format == log_format;
  463. }
  464. }
  465. //____________________________________________________________________________//
  466. void
  467. unit_test_log_t::add_format( output_format log_format )
  468. {
  469. if( s_log_impl().has_entry_in_progress() )
  470. return;
  471. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  472. if( current_logger_data.m_format == log_format) {
  473. current_logger_data.m_enabled = true;
  474. break;
  475. }
  476. }
  477. }
  478. //____________________________________________________________________________//
  479. unit_test_log_formatter*
  480. unit_test_log_t::get_formatter( output_format log_format ) {
  481. BOOST_TEST_FOREACH( unit_test_log_data_helper_impl&, current_logger_data, s_log_impl().m_log_formatter_data ) {
  482. if( current_logger_data.m_format == log_format) {
  483. return current_logger_data.m_log_formatter.get();
  484. }
  485. }
  486. return 0;
  487. }
  488. void
  489. unit_test_log_t::add_formatter( unit_test_log_formatter* the_formatter )
  490. {
  491. // remove only user defined logger
  492. for(unit_test_log_impl::v_formatter_data_t::iterator it(s_log_impl().m_log_formatter_data.begin()),
  493. ite(s_log_impl().m_log_formatter_data.end());
  494. it != ite;
  495. ++it)
  496. {
  497. if( it->m_format == OF_CUSTOM_LOGGER) {
  498. s_log_impl().m_log_formatter_data.erase(it);
  499. break;
  500. }
  501. }
  502. if( the_formatter ) {
  503. s_log_impl().m_log_formatter_data.push_back( unit_test_log_data_helper_impl(the_formatter, OF_CUSTOM_LOGGER, true) );
  504. }
  505. }
  506. void
  507. unit_test_log_t::set_formatter( unit_test_log_formatter* the_formatter )
  508. {
  509. // remove only user defined logger
  510. log_level current_level = invalid_log_level;
  511. std::ostream *current_stream = 0;
  512. output_format previous_format = OF_INVALID;
  513. for(unit_test_log_impl::v_formatter_data_t::iterator it(s_log_impl().m_log_formatter_data.begin()),
  514. ite(s_log_impl().m_log_formatter_data.end());
  515. it != ite;
  516. ++it)
  517. {
  518. if( it->m_enabled ) {
  519. if( current_level == invalid_log_level || it->m_format < previous_format || it->m_format == OF_CUSTOM_LOGGER) {
  520. current_level = it->get_log_level();
  521. current_stream = &(it->stream());
  522. previous_format = it->m_format;
  523. }
  524. }
  525. }
  526. if( the_formatter ) {
  527. add_formatter(the_formatter);
  528. set_format(OF_CUSTOM_LOGGER);
  529. set_threshold_level(OF_CUSTOM_LOGGER, current_level);
  530. set_stream(OF_CUSTOM_LOGGER, *current_stream);
  531. }
  532. }
  533. //____________________________________________________________________________//
  534. // ************************************************************************** //
  535. // ************** unit_test_log_formatter ************** //
  536. // ************************************************************************** //
  537. void
  538. unit_test_log_formatter::log_entry_value( std::ostream& ostr, lazy_ostream const& value )
  539. {
  540. log_entry_value( ostr, (wrap_stringstream().ref() << value).str() );
  541. }
  542. void
  543. unit_test_log_formatter::set_log_level(log_level new_log_level)
  544. {
  545. m_log_level = new_log_level;
  546. }
  547. log_level
  548. unit_test_log_formatter::get_log_level() const
  549. {
  550. return m_log_level;
  551. }
  552. //____________________________________________________________________________//
  553. } // namespace unit_test
  554. } // namespace boost
  555. #include <boost/test/detail/enable_warnings.hpp>
  556. #endif // BOOST_TEST_UNIT_TEST_LOG_IPP_012205GER