basic_logger.hpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. * Copyright Andrey Semashev 2007 - 2015.
  3. * Distributed under the Boost Software License, Version 1.0.
  4. * (See accompanying file LICENSE_1_0.txt or copy at
  5. * http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. /*!
  8. * \file basic_logger.hpp
  9. * \author Andrey Semashev
  10. * \date 08.03.2007
  11. *
  12. * The header contains implementation of a base class for loggers. Convenience macros
  13. * for defining custom loggers are also provided.
  14. */
  15. #ifndef BOOST_LOG_SOURCES_BASIC_LOGGER_HPP_INCLUDED_
  16. #define BOOST_LOG_SOURCES_BASIC_LOGGER_HPP_INCLUDED_
  17. #include <exception>
  18. #include <utility>
  19. #include <ostream>
  20. #include <boost/assert.hpp>
  21. #include <boost/move/core.hpp>
  22. #include <boost/move/utility_core.hpp>
  23. #include <boost/core/addressof.hpp>
  24. #include <boost/type_traits/is_nothrow_swappable.hpp>
  25. #include <boost/type_traits/is_nothrow_move_constructible.hpp>
  26. #include <boost/preprocessor/facilities/empty.hpp>
  27. #include <boost/preprocessor/facilities/identity.hpp>
  28. #include <boost/preprocessor/seq/enum.hpp>
  29. #include <boost/log/detail/config.hpp>
  30. #include <boost/log/detail/parameter_tools.hpp>
  31. #include <boost/log/attributes/attribute_set.hpp>
  32. #include <boost/log/attributes/attribute_name.hpp>
  33. #include <boost/log/attributes/attribute.hpp>
  34. #include <boost/log/core/core.hpp>
  35. #include <boost/log/core/record.hpp>
  36. #include <boost/log/sources/features.hpp>
  37. #include <boost/log/sources/threading_models.hpp>
  38. #include <boost/log/detail/header.hpp>
  39. #ifdef BOOST_HAS_PRAGMA_ONCE
  40. #pragma once
  41. #endif
  42. namespace boost {
  43. BOOST_LOG_OPEN_NAMESPACE
  44. namespace sources {
  45. /*!
  46. * \brief Basic logger class
  47. *
  48. * The \c basic_logger class template serves as a base class for all loggers
  49. * provided by the library. It can also be used as a base for user-defined
  50. * loggers. The template parameters are:
  51. *
  52. * \li \c CharT - logging character type
  53. * \li \c FinalT - final type of the logger that eventually derives from
  54. * the \c basic_logger. There may be other classes in the hierarchy
  55. * between the final class and \c basic_logger.
  56. * \li \c ThreadingModelT - threading model policy. Must provide methods
  57. * of the Boost.Thread locking concept used in \c basic_logger class
  58. * and all its derivatives in the hierarchy up to the \c FinalT class.
  59. * The \c basic_logger class itself requires methods of the
  60. * SharedLockable concept. The threading model policy must also be
  61. * default and copy-constructible and support member function \c swap.
  62. * There are currently two policies provided: \c single_thread_model
  63. * and \c multi_thread_model.
  64. *
  65. * The logger implements fundamental facilities of loggers, such as storing
  66. * source-specific attribute set and formatting log record messages. The basic
  67. * logger interacts with the logging core in order to apply filtering and
  68. * pass records to sinks.
  69. */
  70. template< typename CharT, typename FinalT, typename ThreadingModelT >
  71. class basic_logger :
  72. public ThreadingModelT
  73. {
  74. typedef basic_logger this_type;
  75. BOOST_COPYABLE_AND_MOVABLE_ALT(this_type)
  76. public:
  77. //! Character type
  78. typedef CharT char_type;
  79. //! Final logger type
  80. typedef FinalT final_type;
  81. //! Threading model type
  82. typedef ThreadingModelT threading_model;
  83. #if !defined(BOOST_LOG_NO_THREADS)
  84. //! Lock requirement for the swap_unlocked method
  85. typedef boost::log::aux::multiple_unique_lock2< threading_model, threading_model > swap_lock;
  86. //! Lock requirement for the add_attribute_unlocked method
  87. typedef boost::log::aux::exclusive_lock_guard< threading_model > add_attribute_lock;
  88. //! Lock requirement for the remove_attribute_unlocked method
  89. typedef boost::log::aux::exclusive_lock_guard< threading_model > remove_attribute_lock;
  90. //! Lock requirement for the remove_all_attributes_unlocked method
  91. typedef boost::log::aux::exclusive_lock_guard< threading_model > remove_all_attributes_lock;
  92. //! Lock requirement for the get_attributes method
  93. typedef boost::log::aux::shared_lock_guard< const threading_model > get_attributes_lock;
  94. //! Lock requirement for the open_record_unlocked method
  95. typedef boost::log::aux::shared_lock_guard< threading_model > open_record_lock;
  96. //! Lock requirement for the set_attributes method
  97. typedef boost::log::aux::exclusive_lock_guard< threading_model > set_attributes_lock;
  98. #else
  99. typedef no_lock< threading_model > swap_lock;
  100. typedef no_lock< threading_model > add_attribute_lock;
  101. typedef no_lock< threading_model > remove_attribute_lock;
  102. typedef no_lock< threading_model > remove_all_attributes_lock;
  103. typedef no_lock< const threading_model > get_attributes_lock;
  104. typedef no_lock< threading_model > open_record_lock;
  105. typedef no_lock< threading_model > set_attributes_lock;
  106. #endif
  107. //! Lock requirement for the push_record_unlocked method
  108. typedef no_lock< threading_model > push_record_lock;
  109. private:
  110. //! A pointer to the logging system
  111. core_ptr m_pCore;
  112. //! Logger-specific attribute set
  113. attribute_set m_Attributes;
  114. public:
  115. /*!
  116. * Constructor. Initializes internal data structures of the basic logger class,
  117. * acquires reference to the logging core.
  118. */
  119. basic_logger() :
  120. threading_model(),
  121. m_pCore(core::get())
  122. {
  123. }
  124. /*!
  125. * Copy constructor. Copies all attributes from the source logger.
  126. *
  127. * \note Not thread-safe. The source logger must be locked in the final class before copying.
  128. *
  129. * \param that Source logger
  130. */
  131. basic_logger(basic_logger const& that) :
  132. threading_model(static_cast< threading_model const& >(that)),
  133. m_pCore(that.m_pCore),
  134. m_Attributes(that.m_Attributes)
  135. {
  136. }
  137. /*!
  138. * Move constructor. Moves all attributes from the source logger.
  139. *
  140. * \note Not thread-safe. The source logger must be locked in the final class before copying.
  141. *
  142. * \param that Source logger
  143. */
  144. basic_logger(BOOST_RV_REF(basic_logger) that) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< threading_model >::value &&
  145. boost::is_nothrow_move_constructible< core_ptr >::value &&
  146. boost::is_nothrow_move_constructible< attribute_set >::value) :
  147. threading_model(boost::move(static_cast< threading_model& >(that))),
  148. m_pCore(boost::move(that.m_pCore)),
  149. m_Attributes(boost::move(that.m_Attributes))
  150. {
  151. }
  152. /*!
  153. * Constructor with named arguments. The constructor ignores all arguments. The result of
  154. * construction is equivalent to default construction.
  155. */
  156. template< typename ArgsT >
  157. explicit basic_logger(ArgsT const&) :
  158. threading_model(),
  159. m_pCore(core::get())
  160. {
  161. }
  162. protected:
  163. /*!
  164. * An accessor to the logging system pointer
  165. */
  166. core_ptr const& core() const { return m_pCore; }
  167. /*!
  168. * An accessor to the logger attributes
  169. */
  170. attribute_set& attributes() { return m_Attributes; }
  171. /*!
  172. * An accessor to the logger attributes
  173. */
  174. attribute_set const& attributes() const { return m_Attributes; }
  175. /*!
  176. * An accessor to the threading model base
  177. */
  178. threading_model& get_threading_model() BOOST_NOEXCEPT { return *this; }
  179. /*!
  180. * An accessor to the threading model base
  181. */
  182. threading_model const& get_threading_model() const BOOST_NOEXCEPT { return *this; }
  183. /*!
  184. * An accessor to the final logger
  185. */
  186. final_type* final_this() BOOST_NOEXCEPT
  187. {
  188. BOOST_LOG_ASSUME(this != NULL);
  189. return static_cast< final_type* >(this);
  190. }
  191. /*!
  192. * An accessor to the final logger
  193. */
  194. final_type const* final_this() const BOOST_NOEXCEPT
  195. {
  196. BOOST_LOG_ASSUME(this != NULL);
  197. return static_cast< final_type const* >(this);
  198. }
  199. /*!
  200. * Unlocked \c swap
  201. */
  202. void swap_unlocked(basic_logger& that)
  203. {
  204. get_threading_model().swap(that.get_threading_model());
  205. m_Attributes.swap(that.m_Attributes);
  206. }
  207. /*!
  208. * Unlocked \c add_attribute
  209. */
  210. std::pair< attribute_set::iterator, bool > add_attribute_unlocked(attribute_name const& name, attribute const& attr)
  211. {
  212. return m_Attributes.insert(name, attr);
  213. }
  214. /*!
  215. * Unlocked \c remove_attribute
  216. */
  217. void remove_attribute_unlocked(attribute_set::iterator it)
  218. {
  219. m_Attributes.erase(it);
  220. }
  221. /*!
  222. * Unlocked \c remove_all_attributes
  223. */
  224. void remove_all_attributes_unlocked()
  225. {
  226. m_Attributes.clear();
  227. }
  228. /*!
  229. * Unlocked \c open_record
  230. */
  231. record open_record_unlocked()
  232. {
  233. return m_pCore->open_record(m_Attributes);
  234. }
  235. /*!
  236. * Unlocked \c open_record
  237. */
  238. template< typename ArgsT >
  239. record open_record_unlocked(ArgsT const&)
  240. {
  241. return m_pCore->open_record(m_Attributes);
  242. }
  243. /*!
  244. * Unlocked \c push_record
  245. */
  246. void push_record_unlocked(BOOST_RV_REF(record) rec)
  247. {
  248. m_pCore->push_record(boost::move(rec));
  249. }
  250. /*!
  251. * Unlocked \c get_attributes
  252. */
  253. attribute_set get_attributes_unlocked() const
  254. {
  255. return m_Attributes;
  256. }
  257. /*!
  258. * Unlocked \c set_attributes
  259. */
  260. void set_attributes_unlocked(attribute_set const& attrs)
  261. {
  262. m_Attributes = attrs;
  263. }
  264. //! Assignment is closed (should be implemented through copy and swap in the final class)
  265. BOOST_DELETED_FUNCTION(basic_logger& operator= (basic_logger const&))
  266. };
  267. /*!
  268. * Free-standing swap for all loggers
  269. */
  270. template< typename CharT, typename FinalT, typename ThreadingModelT >
  271. inline void swap(
  272. basic_logger< CharT, FinalT, ThreadingModelT >& left,
  273. basic_logger< CharT, FinalT, ThreadingModelT >& right) BOOST_NOEXCEPT_IF(boost::is_nothrow_swappable< FinalT >::value)
  274. {
  275. static_cast< FinalT& >(left).swap(static_cast< FinalT& >(right));
  276. }
  277. /*!
  278. * \brief A composite logger that inherits a number of features
  279. *
  280. * The composite logger is a helper class that simplifies feature composition into the final logger.
  281. * The user's logger class is expected to derive from the composite logger class, instantiated with
  282. * the character type, the user's logger class, the threading model and the list of the required features.
  283. * The former three parameters are passed to the \c basic_logger class template. The feature list
  284. * must be an MPL type sequence, where each element is a unary MPL metafunction class, that upon
  285. * applying on its argument results in a logging feature class that derives from the argument.
  286. * Every logger feature provided by the library can participate in the feature list.
  287. */
  288. template< typename CharT, typename FinalT, typename ThreadingModelT, typename FeaturesT >
  289. class basic_composite_logger :
  290. public boost::log::sources::aux::inherit_features<
  291. basic_logger< CharT, FinalT, ThreadingModelT >,
  292. FeaturesT
  293. >::type
  294. {
  295. private:
  296. //! Base type (the hierarchy of features)
  297. typedef typename boost::log::sources::aux::inherit_features<
  298. basic_logger< CharT, FinalT, ThreadingModelT >,
  299. FeaturesT
  300. >::type base_type;
  301. protected:
  302. //! The composite logger type (for use in the user's logger class)
  303. typedef basic_composite_logger logger_base;
  304. BOOST_COPYABLE_AND_MOVABLE_ALT(logger_base)
  305. public:
  306. //! Threading model being used
  307. typedef typename base_type::threading_model threading_model;
  308. //! Lock requirement for the swap_unlocked method
  309. typedef typename base_type::swap_lock swap_lock;
  310. #if !defined(BOOST_LOG_NO_THREADS)
  311. public:
  312. /*!
  313. * Default constructor (default-constructs all features)
  314. */
  315. basic_composite_logger() {}
  316. /*!
  317. * Copy constructor
  318. */
  319. basic_composite_logger(basic_composite_logger const& that) :
  320. base_type
  321. ((
  322. boost::log::aux::shared_lock_guard< const threading_model >(that.get_threading_model()),
  323. static_cast< base_type const& >(that)
  324. ))
  325. {
  326. }
  327. /*!
  328. * Move constructor
  329. */
  330. basic_composite_logger(BOOST_RV_REF(logger_base) that) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< base_type >::value) :
  331. base_type(boost::move(static_cast< base_type& >(that)))
  332. {
  333. }
  334. /*!
  335. * Constructor with named parameters
  336. */
  337. template< typename ArgsT >
  338. explicit basic_composite_logger(ArgsT const& args) : base_type(args)
  339. {
  340. }
  341. /*!
  342. * The method adds an attribute to the source-specific attribute set. The attribute will be implicitly added to
  343. * every log record made with the current logger.
  344. *
  345. * \param name The attribute name.
  346. * \param attr The attribute factory.
  347. * \return A pair of values. If the second member is \c true, then the attribute is added and the first member points to the
  348. * attribute. Otherwise the attribute was not added and the first member points to the attribute that prevents
  349. * addition.
  350. */
  351. std::pair< attribute_set::iterator, bool > add_attribute(attribute_name const& name, attribute const& attr)
  352. {
  353. typename base_type::add_attribute_lock lock(base_type::get_threading_model());
  354. return base_type::add_attribute_unlocked(name, attr);
  355. }
  356. /*!
  357. * The method removes an attribute from the source-specific attribute set.
  358. *
  359. * \pre The attribute was added with the add_attribute call for this instance of the logger.
  360. * \post The attribute is no longer registered as a source-specific attribute for this logger. The iterator is invalidated after removal.
  361. *
  362. * \param it Iterator to the previously added attribute.
  363. */
  364. void remove_attribute(attribute_set::iterator it)
  365. {
  366. typename base_type::remove_attribute_lock lock(base_type::get_threading_model());
  367. base_type::remove_attribute_unlocked(it);
  368. }
  369. /*!
  370. * The method removes all attributes from the logger. All iterators and references to the removed attributes are invalidated.
  371. */
  372. void remove_all_attributes()
  373. {
  374. typename base_type::remove_all_attributes_lock lock(base_type::get_threading_model());
  375. base_type::remove_all_attributes_unlocked();
  376. }
  377. /*!
  378. * The method retrieves a copy of a set with all attributes from the logger.
  379. *
  380. * \return The copy of the attribute set. Attributes are shallow-copied.
  381. */
  382. attribute_set get_attributes() const
  383. {
  384. typename base_type::get_attributes_lock lock(base_type::get_threading_model());
  385. return base_type::get_attributes_unlocked();
  386. }
  387. /*!
  388. * The method installs the whole attribute set into the logger. All iterators and references to elements of
  389. * the previous set are invalidated. Iterators to the \a attrs set are not valid to be used with the logger (that is,
  390. * the logger owns a copy of \a attrs after completion).
  391. *
  392. * \param attrs The set of attributes to install into the logger. Attributes are shallow-copied.
  393. */
  394. void set_attributes(attribute_set const& attrs)
  395. {
  396. typename base_type::set_attributes_lock lock(base_type::get_threading_model());
  397. base_type::set_attributes_unlocked(attrs);
  398. }
  399. /*!
  400. * The method opens a new log record in the logging core.
  401. *
  402. * \return A valid record handle if the logging record is opened successfully, an invalid handle otherwise.
  403. */
  404. record open_record()
  405. {
  406. // Perform a quick check first
  407. if (this->core()->get_logging_enabled())
  408. {
  409. typename base_type::open_record_lock lock(base_type::get_threading_model());
  410. return base_type::open_record_unlocked(boost::log::aux::empty_arg_list());
  411. }
  412. else
  413. return record();
  414. }
  415. /*!
  416. * The method opens a new log record in the logging core.
  417. *
  418. * \param args A set of additional named arguments. The parameter is ignored.
  419. * \return A valid record handle if the logging record is opened successfully, an invalid handle otherwise.
  420. */
  421. template< typename ArgsT >
  422. record open_record(ArgsT const& args)
  423. {
  424. // Perform a quick check first
  425. if (this->core()->get_logging_enabled())
  426. {
  427. typename base_type::open_record_lock lock(base_type::get_threading_model());
  428. return base_type::open_record_unlocked(args);
  429. }
  430. else
  431. return record();
  432. }
  433. /*!
  434. * The method pushes the constructed message to the logging core
  435. *
  436. * \param rec The log record with the formatted message
  437. */
  438. void push_record(BOOST_RV_REF(record) rec)
  439. {
  440. typename base_type::push_record_lock lock(base_type::get_threading_model());
  441. base_type::push_record_unlocked(boost::move(rec));
  442. }
  443. /*!
  444. * Thread-safe implementation of swap
  445. */
  446. void swap(basic_composite_logger& that)
  447. {
  448. swap_lock lock(base_type::get_threading_model(), that.get_threading_model());
  449. base_type::swap_unlocked(static_cast< base_type& >(that));
  450. }
  451. protected:
  452. /*!
  453. * Assignment for the final class. Threadsafe, provides strong exception guarantee.
  454. */
  455. FinalT& assign(FinalT const& that)
  456. {
  457. BOOST_LOG_ASSUME(this != NULL);
  458. if (static_cast< FinalT* >(this) != boost::addressof(that))
  459. {
  460. // We'll have to explicitly create the copy in order to make sure it's unlocked when we attempt to lock *this
  461. FinalT tmp(that);
  462. boost::log::aux::exclusive_lock_guard< threading_model > lock(base_type::get_threading_model());
  463. base_type::swap_unlocked(tmp);
  464. }
  465. return static_cast< FinalT& >(*this);
  466. }
  467. };
  468. //! An optimized composite logger version with no multithreading support
  469. template< typename CharT, typename FinalT, typename FeaturesT >
  470. class basic_composite_logger< CharT, FinalT, single_thread_model, FeaturesT > :
  471. public boost::log::sources::aux::inherit_features<
  472. basic_logger< CharT, FinalT, single_thread_model >,
  473. FeaturesT
  474. >::type
  475. {
  476. private:
  477. typedef typename boost::log::sources::aux::inherit_features<
  478. basic_logger< CharT, FinalT, single_thread_model >,
  479. FeaturesT
  480. >::type base_type;
  481. protected:
  482. typedef basic_composite_logger logger_base;
  483. BOOST_COPYABLE_AND_MOVABLE_ALT(logger_base)
  484. public:
  485. typedef typename base_type::threading_model threading_model;
  486. #endif // !defined(BOOST_LOG_NO_THREADS)
  487. public:
  488. basic_composite_logger() {}
  489. basic_composite_logger(basic_composite_logger const& that) :
  490. base_type(static_cast< base_type const& >(that))
  491. {
  492. }
  493. basic_composite_logger(BOOST_RV_REF(logger_base) that) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< base_type >::value) :
  494. base_type(boost::move(static_cast< base_type& >(that)))
  495. {
  496. }
  497. template< typename ArgsT >
  498. explicit basic_composite_logger(ArgsT const& args) : base_type(args)
  499. {
  500. }
  501. std::pair< attribute_set::iterator, bool > add_attribute(attribute_name const& name, attribute const& attr)
  502. {
  503. return base_type::add_attribute_unlocked(name, attr);
  504. }
  505. void remove_attribute(attribute_set::iterator it)
  506. {
  507. base_type::remove_attribute_unlocked(it);
  508. }
  509. void remove_all_attributes()
  510. {
  511. base_type::remove_all_attributes_unlocked();
  512. }
  513. attribute_set get_attributes() const
  514. {
  515. return base_type::get_attributes_unlocked();
  516. }
  517. void set_attributes(attribute_set const& attrs)
  518. {
  519. base_type::set_attributes_unlocked(attrs);
  520. }
  521. record open_record()
  522. {
  523. // Perform a quick check first
  524. if (this->core()->get_logging_enabled())
  525. return base_type::open_record_unlocked(boost::log::aux::empty_arg_list());
  526. else
  527. return record();
  528. }
  529. template< typename ArgsT >
  530. record open_record(ArgsT const& args)
  531. {
  532. // Perform a quick check first
  533. if (this->core()->get_logging_enabled())
  534. return base_type::open_record_unlocked(args);
  535. else
  536. return record();
  537. }
  538. void push_record(BOOST_RV_REF(record) rec)
  539. {
  540. base_type::push_record_unlocked(boost::move(rec));
  541. }
  542. void swap(basic_composite_logger& that)
  543. {
  544. base_type::swap_unlocked(static_cast< base_type& >(that));
  545. }
  546. protected:
  547. FinalT& assign(FinalT that)
  548. {
  549. base_type::swap_unlocked(that);
  550. return static_cast< FinalT& >(*this);
  551. }
  552. };
  553. #ifndef BOOST_LOG_DOXYGEN_PASS
  554. #define BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_IMPL(class_type, typename_keyword)\
  555. public:\
  556. BOOST_DEFAULTED_FUNCTION(class_type(), {})\
  557. class_type(class_type const& that) : class_type::logger_base(\
  558. static_cast< typename_keyword() class_type::logger_base const& >(that)) {}\
  559. class_type(BOOST_RV_REF(class_type) that) BOOST_NOEXCEPT_IF(boost::is_nothrow_move_constructible< typename_keyword() class_type::logger_base >::value) : class_type::logger_base(\
  560. ::boost::move(static_cast< typename_keyword() class_type::logger_base& >(that))) {}\
  561. BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_FORWARD(class_type, class_type::logger_base)\
  562. #endif // BOOST_LOG_DOXYGEN_PASS
  563. #define BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS(class_type)\
  564. BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_IMPL(class_type, BOOST_PP_EMPTY)
  565. #define BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_TEMPLATE(class_type)\
  566. BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_IMPL(class_type, BOOST_PP_IDENTITY(typename))
  567. #define BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT(class_type)\
  568. public:\
  569. class_type& operator= (BOOST_COPY_ASSIGN_REF(class_type) that)\
  570. {\
  571. return class_type::logger_base::assign(static_cast< class_type const& >(that));\
  572. }\
  573. class_type& operator= (BOOST_RV_REF(class_type) that)\
  574. {\
  575. BOOST_LOG_EXPR_IF_MT(::boost::log::aux::exclusive_lock_guard< class_type::threading_model > lock(this->get_threading_model());)\
  576. this->swap_unlocked(that);\
  577. return *this;\
  578. }
  579. #define BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT_TEMPLATE(class_type)\
  580. public:\
  581. class_type& operator= (BOOST_COPY_ASSIGN_REF(class_type) that)\
  582. {\
  583. return class_type::logger_base::assign(static_cast< class_type const& >(that));\
  584. }\
  585. class_type& operator= (BOOST_RV_REF(class_type) that)\
  586. {\
  587. BOOST_LOG_EXPR_IF_MT(::boost::log::aux::exclusive_lock_guard< typename class_type::threading_model > lock(this->get_threading_model());)\
  588. this->swap_unlocked(that);\
  589. return *this;\
  590. }
  591. #define BOOST_LOG_FORWARD_LOGGER_MEMBERS(class_type)\
  592. BOOST_COPYABLE_AND_MOVABLE(class_type)\
  593. BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS(class_type)\
  594. BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT(class_type)
  595. #define BOOST_LOG_FORWARD_LOGGER_MEMBERS_TEMPLATE(class_type)\
  596. BOOST_COPYABLE_AND_MOVABLE(class_type)\
  597. BOOST_LOG_FORWARD_LOGGER_CONSTRUCTORS_TEMPLATE(class_type)\
  598. BOOST_LOG_FORWARD_LOGGER_ASSIGNMENT_TEMPLATE(class_type)
  599. } // namespace sources
  600. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  601. } // namespace boost
  602. /*!
  603. * \brief The macro declares a logger class that inherits a number of base classes
  604. *
  605. * \param type_name The name of the logger class to declare
  606. * \param char_type The character type of the logger. Either char or wchar_t expected.
  607. * \param base_seq A Boost.Preprocessor sequence of type identifiers of the base classes templates
  608. * \param threading A threading model class
  609. */
  610. #define BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char_type, base_seq, threading)\
  611. class type_name :\
  612. public ::boost::log::sources::basic_composite_logger<\
  613. char_type,\
  614. type_name,\
  615. threading,\
  616. ::boost::log::sources::features< BOOST_PP_SEQ_ENUM(base_seq) >\
  617. >\
  618. {\
  619. BOOST_LOG_FORWARD_LOGGER_MEMBERS(type_name)\
  620. }
  621. #ifdef BOOST_LOG_USE_CHAR
  622. /*!
  623. * \brief The macro declares a narrow-char logger class that inherits a number of base classes
  624. *
  625. * Equivalent to BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char, base_seq, single_thread_model)
  626. *
  627. * \param type_name The name of the logger class to declare
  628. * \param base_seq A Boost.Preprocessor sequence of type identifiers of the base classes templates
  629. */
  630. #define BOOST_LOG_DECLARE_LOGGER(type_name, base_seq)\
  631. BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char, base_seq, ::boost::log::sources::single_thread_model)
  632. #if !defined(BOOST_LOG_NO_THREADS)
  633. /*!
  634. * \brief The macro declares a narrow-char thread-safe logger class that inherits a number of base classes
  635. *
  636. * Equivalent to <tt>BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char, base_seq, multi_thread_model< shared_mutex >)</tt>
  637. *
  638. * \param type_name The name of the logger class to declare
  639. * \param base_seq A Boost.Preprocessor sequence of type identifiers of the base classes templates
  640. */
  641. #define BOOST_LOG_DECLARE_LOGGER_MT(type_name, base_seq)\
  642. BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, char, base_seq,\
  643. ::boost::log::sources::multi_thread_model< ::boost::shared_mutex >)
  644. #endif // !defined(BOOST_LOG_NO_THREADS)
  645. #endif // BOOST_LOG_USE_CHAR
  646. #ifdef BOOST_LOG_USE_WCHAR_T
  647. /*!
  648. * \brief The macro declares a wide-char logger class that inherits a number of base classes
  649. *
  650. * Equivalent to BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, wchar_t, base_seq, single_thread_model)
  651. *
  652. * \param type_name The name of the logger class to declare
  653. * \param base_seq A Boost.Preprocessor sequence of type identifiers of the base classes templates
  654. */
  655. #define BOOST_LOG_DECLARE_WLOGGER(type_name, base_seq)\
  656. BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, wchar_t, base_seq, ::boost::log::sources::single_thread_model)
  657. #if !defined(BOOST_LOG_NO_THREADS)
  658. /*!
  659. * \brief The macro declares a wide-char thread-safe logger class that inherits a number of base classes
  660. *
  661. * Equivalent to <tt>BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, wchar_t, base_seq, multi_thread_model< shared_mutex >)</tt>
  662. *
  663. * \param type_name The name of the logger class to declare
  664. * \param base_seq A Boost.Preprocessor sequence of type identifiers of the base classes templates
  665. */
  666. #define BOOST_LOG_DECLARE_WLOGGER_MT(type_name, base_seq)\
  667. BOOST_LOG_DECLARE_LOGGER_TYPE(type_name, wchar_t, base_seq,\
  668. ::boost::log::sources::multi_thread_model< ::boost::shared_mutex >)
  669. #endif // !defined(BOOST_LOG_NO_THREADS)
  670. #endif // BOOST_LOG_USE_WCHAR_T
  671. #include <boost/log/detail/footer.hpp>
  672. #endif // BOOST_LOG_SOURCES_BASIC_LOGGER_HPP_INCLUDED_