basic_logger.hpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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/preprocessor/facilities/empty.hpp>
  25. #include <boost/preprocessor/facilities/identity.hpp>
  26. #include <boost/preprocessor/repetition/enum_params.hpp>
  27. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  28. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  29. #include <boost/preprocessor/seq/enum.hpp>
  30. #include <boost/log/detail/config.hpp>
  31. #include <boost/log/detail/parameter_tools.hpp>
  32. #include <boost/log/attributes/attribute_set.hpp>
  33. #include <boost/log/attributes/attribute_name.hpp>
  34. #include <boost/log/attributes/attribute.hpp>
  35. #include <boost/log/core/core.hpp>
  36. #include <boost/log/core/record.hpp>
  37. #include <boost/log/sources/features.hpp>
  38. #include <boost/log/sources/threading_models.hpp>
  39. #include <boost/log/detail/header.hpp>
  40. #ifdef BOOST_HAS_PRAGMA_ONCE
  41. #pragma once
  42. #endif
  43. namespace boost {
  44. BOOST_LOG_OPEN_NAMESPACE
  45. namespace sources {
  46. /*!
  47. * \brief Basic logger class
  48. *
  49. * The \c basic_logger class template serves as a base class for all loggers
  50. * provided by the library. It can also be used as a base for user-defined
  51. * loggers. The template parameters are:
  52. *
  53. * \li \c CharT - logging character type
  54. * \li \c FinalT - final type of the logger that eventually derives from
  55. * the \c basic_logger. There may be other classes in the hierarchy
  56. * between the final class and \c basic_logger.
  57. * \li \c ThreadingModelT - threading model policy. Must provide methods
  58. * of the Boost.Thread locking concept used in \c basic_logger class
  59. * and all its derivatives in the hierarchy up to the \c FinalT class.
  60. * The \c basic_logger class itself requires methods of the
  61. * SharedLockable concept. The threading model policy must also be
  62. * default and copy-constructible and support member function \c swap.
  63. * There are currently two policies provided: \c single_thread_model
  64. * and \c multi_thread_model.
  65. *
  66. * The logger implements fundamental facilities of loggers, such as storing
  67. * source-specific attribute set and formatting log record messages. The basic
  68. * logger interacts with the logging core in order to apply filtering and
  69. * pass records to sinks.
  70. */
  71. template< typename CharT, typename FinalT, typename ThreadingModelT >
  72. class basic_logger :
  73. public ThreadingModelT
  74. {
  75. typedef basic_logger this_type;
  76. BOOST_COPYABLE_AND_MOVABLE_ALT(this_type)
  77. public:
  78. //! Character type
  79. typedef CharT char_type;
  80. //! Final logger type
  81. typedef FinalT final_type;
  82. //! Threading model type
  83. typedef ThreadingModelT threading_model;
  84. #if !defined(BOOST_LOG_NO_THREADS)
  85. //! Lock requirement for the swap_unlocked method
  86. typedef boost::log::aux::exclusive_lock_guard< threading_model > swap_lock;
  87. //! Lock requirement for the add_attribute_unlocked method
  88. typedef boost::log::aux::exclusive_lock_guard< threading_model > add_attribute_lock;
  89. //! Lock requirement for the remove_attribute_unlocked method
  90. typedef boost::log::aux::exclusive_lock_guard< threading_model > remove_attribute_lock;
  91. //! Lock requirement for the remove_all_attributes_unlocked method
  92. typedef boost::log::aux::exclusive_lock_guard< threading_model > remove_all_attributes_lock;
  93. //! Lock requirement for the get_attributes method
  94. typedef boost::log::aux::shared_lock_guard< const threading_model > get_attributes_lock;
  95. //! Lock requirement for the open_record_unlocked method
  96. typedef boost::log::aux::shared_lock_guard< threading_model > open_record_lock;
  97. //! Lock requirement for the set_attributes method
  98. typedef boost::log::aux::exclusive_lock_guard< threading_model > set_attributes_lock;
  99. #else
  100. typedef no_lock< threading_model > swap_lock;
  101. typedef no_lock< threading_model > add_attribute_lock;
  102. typedef no_lock< threading_model > remove_attribute_lock;
  103. typedef no_lock< threading_model > remove_all_attributes_lock;
  104. typedef no_lock< const threading_model > get_attributes_lock;
  105. typedef no_lock< threading_model > open_record_lock;
  106. typedef no_lock< threading_model > set_attributes_lock;
  107. #endif
  108. //! Lock requirement for the push_record_unlocked method
  109. typedef no_lock< threading_model > push_record_lock;
  110. private:
  111. //! A pointer to the logging system
  112. core_ptr m_pCore;
  113. //! Logger-specific attribute set
  114. attribute_set m_Attributes;
  115. public:
  116. /*!
  117. * Constructor. Initializes internal data structures of the basic logger class,
  118. * acquires reference to the logging core.
  119. */
  120. basic_logger() :
  121. threading_model(),
  122. m_pCore(core::get())
  123. {
  124. }
  125. /*!
  126. * Copy constructor. Copies all attributes from the source logger.
  127. *
  128. * \note Not thread-safe. The source logger must be locked in the final class before copying.
  129. *
  130. * \param that Source logger
  131. */
  132. basic_logger(basic_logger const& that) :
  133. threading_model(static_cast< threading_model const& >(that)),
  134. m_pCore(core::get()),
  135. m_Attributes(that.m_Attributes)
  136. {
  137. }
  138. /*!
  139. * Move constructor. Moves all attributes from the source logger.
  140. *
  141. * \note Not thread-safe. The source logger must be locked in the final class before copying.
  142. *
  143. * \param that Source logger
  144. */
  145. basic_logger(BOOST_RV_REF(basic_logger) that) :
  146. threading_model(boost::move(static_cast< threading_model& >(that)))
  147. {
  148. m_pCore.swap(that.m_pCore);
  149. m_Attributes.swap(that.m_Attributes);
  150. }
  151. /*!
  152. * Constructor with named arguments. The constructor ignores all arguments. The result of
  153. * construction is equivalent to default construction.
  154. */
  155. template< typename ArgsT >
  156. explicit basic_logger(ArgsT const&) :
  157. threading_model(),
  158. m_pCore(core::get())
  159. {
  160. }
  161. protected:
  162. /*!
  163. * An accessor to the logging system pointer
  164. */
  165. core_ptr const& core() const { return m_pCore; }
  166. /*!
  167. * An accessor to the logger attributes
  168. */
  169. attribute_set& attributes() { return m_Attributes; }
  170. /*!
  171. * An accessor to the logger attributes
  172. */
  173. attribute_set const& attributes() const { return m_Attributes; }
  174. /*!
  175. * An accessor to the threading model base
  176. */
  177. threading_model& get_threading_model() { return *this; }
  178. /*!
  179. * An accessor to the threading model base
  180. */
  181. threading_model const& get_threading_model() const { return *this; }
  182. /*!
  183. * An accessor to the final logger
  184. */
  185. final_type* final_this()
  186. {
  187. BOOST_LOG_ASSUME(this != NULL);
  188. return static_cast< final_type* >(this);
  189. }
  190. /*!
  191. * An accessor to the final logger
  192. */
  193. final_type const* final_this() const
  194. {
  195. BOOST_LOG_ASSUME(this != NULL);
  196. return static_cast< final_type const* >(this);
  197. }
  198. /*!
  199. * Unlocked \c swap
  200. */
  201. void swap_unlocked(basic_logger& that)
  202. {
  203. get_threading_model().swap(that.get_threading_model());
  204. m_Attributes.swap(that.m_Attributes);
  205. }
  206. /*!
  207. * Unlocked \c add_attribute
  208. */
  209. std::pair< attribute_set::iterator, bool > add_attribute_unlocked(attribute_name const& name, attribute const& attr)
  210. {
  211. return m_Attributes.insert(name, attr);
  212. }
  213. /*!
  214. * Unlocked \c remove_attribute
  215. */
  216. void remove_attribute_unlocked(attribute_set::iterator it)
  217. {
  218. m_Attributes.erase(it);
  219. }
  220. /*!
  221. * Unlocked \c remove_all_attributes
  222. */
  223. void remove_all_attributes_unlocked()
  224. {
  225. m_Attributes.clear();
  226. }
  227. /*!
  228. * Unlocked \c open_record
  229. */
  230. record open_record_unlocked()
  231. {
  232. return m_pCore->open_record(m_Attributes);
  233. }
  234. /*!
  235. * Unlocked \c open_record
  236. */
  237. template< typename ArgsT >
  238. record open_record_unlocked(ArgsT const&)
  239. {
  240. return m_pCore->open_record(m_Attributes);
  241. }
  242. /*!
  243. * Unlocked \c push_record
  244. */
  245. void push_record_unlocked(BOOST_RV_REF(record) rec)
  246. {
  247. m_pCore->push_record(boost::move(rec));
  248. }
  249. /*!
  250. * Unlocked \c get_attributes
  251. */
  252. attribute_set get_attributes_unlocked() const
  253. {
  254. return m_Attributes;
  255. }
  256. /*!
  257. * Unlocked \c set_attributes
  258. */
  259. void set_attributes_unlocked(attribute_set const& attrs)
  260. {
  261. m_Attributes = attrs;
  262. }
  263. //! Assignment is closed (should be implemented through copy and swap in the final class)
  264. BOOST_DELETED_FUNCTION(basic_logger& operator= (basic_logger const&))
  265. };
  266. /*!
  267. * Free-standing swap for all loggers
  268. */
  269. template< typename CharT, typename FinalT, typename ThreadingModelT >
  270. inline void swap(
  271. basic_logger< CharT, FinalT, ThreadingModelT >& left,
  272. basic_logger< CharT, FinalT, ThreadingModelT >& right)
  273. {
  274. static_cast< FinalT& >(left).swap(static_cast< FinalT& >(right));
  275. }
  276. /*!
  277. * \brief A composite logger that inherits a number of features
  278. *
  279. * The composite logger is a helper class that simplifies feature composition into the final logger.
  280. * The user's logger class is expected to derive from the composite logger class, instantiated with
  281. * the character type, the user's logger class, the threading model and the list of the required features.
  282. * The former three parameters are passed to the \c basic_logger class template. The feature list
  283. * must be an MPL type sequence, where each element is a unary MPL metafunction class, that upon
  284. * applying on its argument results in a logging feature class that derives from the argument.
  285. * Every logger feature provided by the library can participate in the feature list.
  286. */
  287. template< typename CharT, typename FinalT, typename ThreadingModelT, typename FeaturesT >
  288. class basic_composite_logger :
  289. public boost::log::sources::aux::inherit_features<
  290. basic_logger< CharT, FinalT, ThreadingModelT >,
  291. FeaturesT
  292. >::type
  293. {
  294. private:
  295. //! Base type (the hierarchy of features)
  296. typedef typename boost::log::sources::aux::inherit_features<
  297. basic_logger< CharT, FinalT, ThreadingModelT >,
  298. FeaturesT
  299. >::type base_type;
  300. protected:
  301. //! The composite logger type (for use in the user's logger class)
  302. typedef basic_composite_logger logger_base;
  303. BOOST_COPYABLE_AND_MOVABLE_ALT(logger_base)
  304. public:
  305. //! Threading model being used
  306. typedef typename base_type::threading_model threading_model;
  307. #if !defined(BOOST_LOG_NO_THREADS)
  308. public:
  309. /*!
  310. * Default constructor (default-constructs all features)
  311. */
  312. basic_composite_logger() {}
  313. /*!
  314. * Copy constructor
  315. */
  316. basic_composite_logger(basic_composite_logger const& that) :
  317. base_type
  318. ((
  319. boost::log::aux::shared_lock_guard< const threading_model >(that.get_threading_model()),
  320. static_cast< base_type const& >(that)
  321. ))
  322. {
  323. }
  324. /*!
  325. * Move constructor
  326. */
  327. basic_composite_logger(BOOST_RV_REF(logger_base) that) :
  328. base_type(boost::move(static_cast< base_type& >(that)))
  329. {
  330. }
  331. /*!
  332. * Constructor with named parameters
  333. */
  334. template< typename ArgsT >
  335. explicit basic_composite_logger(ArgsT const& args) : base_type(args)
  336. {
  337. }
  338. /*!
  339. * The method adds an attribute to the source-specific attribute set. The attribute will be implicitly added to
  340. * every log record made with the current logger.
  341. *
  342. * \param name The attribute name.
  343. * \param attr The attribute factory.
  344. * \return A pair of values. If the second member is \c true, then the attribute is added and the first member points to the
  345. * attribute. Otherwise the attribute was not added and the first member points to the attribute that prevents
  346. * addition.
  347. */
  348. std::pair< attribute_set::iterator, bool > add_attribute(attribute_name const& name, attribute const& attr)
  349. {
  350. typename base_type::add_attribute_lock lock(base_type::get_threading_model());
  351. return base_type::add_attribute_unlocked(name, attr);
  352. }
  353. /*!
  354. * The method removes an attribute from the source-specific attribute set.
  355. *
  356. * \pre The attribute was added with the add_attribute call for this instance of the logger.
  357. * \post The attribute is no longer registered as a source-specific attribute for this logger. The iterator is invalidated after removal.
  358. *
  359. * \param it Iterator to the previously added attribute.
  360. */
  361. void remove_attribute(attribute_set::iterator it)
  362. {
  363. typename base_type::remove_attribute_lock lock(base_type::get_threading_model());
  364. base_type::remove_attribute_unlocked(it);
  365. }
  366. /*!
  367. * The method removes all attributes from the logger. All iterators and references to the removed attributes are invalidated.
  368. */
  369. void remove_all_attributes()
  370. {
  371. typename base_type::remove_all_attributes_lock lock(base_type::get_threading_model());
  372. base_type::remove_all_attributes_unlocked();
  373. }
  374. /*!
  375. * The method retrieves a copy of a set with all attributes from the logger.
  376. *
  377. * \return The copy of the attribute set. Attributes are shallow-copied.
  378. */
  379. attribute_set get_attributes() const
  380. {
  381. typename base_type::get_attributes_lock lock(base_type::get_threading_model());
  382. return base_type::get_attributes_unlocked();
  383. }
  384. /*!
  385. * The method installs the whole attribute set into the logger. All iterators and references to elements of
  386. * the previous set are invalidated. Iterators to the \a attrs set are not valid to be used with the logger (that is,
  387. * the logger owns a copy of \a attrs after completion).
  388. *
  389. * \param attrs The set of attributes to install into the logger. Attributes are shallow-copied.
  390. */
  391. void set_attributes(attribute_set const& attrs)
  392. {
  393. typename base_type::set_attributes_lock lock(base_type::get_threading_model());
  394. base_type::set_attributes_unlocked(attrs);
  395. }
  396. /*!
  397. * The method opens a new log record in the logging core.
  398. *
  399. * \return A valid record handle if the logging record is opened successfully, an invalid handle otherwise.
  400. */
  401. record open_record()
  402. {
  403. // Perform a quick check first
  404. if (this->core()->get_logging_enabled())
  405. {
  406. typename base_type::open_record_lock lock(base_type::get_threading_model());
  407. return base_type::open_record_unlocked(boost::log::aux::empty_arg_list());
  408. }
  409. else
  410. return record();
  411. }
  412. /*!
  413. * The method opens a new log record in the logging core.
  414. *
  415. * \param args A set of additional named arguments. The parameter is ignored.
  416. * \return A valid record handle if the logging record is opened successfully, an invalid handle otherwise.
  417. */
  418. template< typename ArgsT >
  419. record open_record(ArgsT const& args)
  420. {
  421. // Perform a quick check first
  422. if (this->core()->get_logging_enabled())
  423. {
  424. typename base_type::open_record_lock lock(base_type::get_threading_model());
  425. return base_type::open_record_unlocked(args);
  426. }
  427. else
  428. return record();
  429. }
  430. /*!
  431. * The method pushes the constructed message to the logging core
  432. *
  433. * \param rec The log record with the formatted message
  434. */
  435. void push_record(BOOST_RV_REF(record) rec)
  436. {
  437. typename base_type::push_record_lock lock(base_type::get_threading_model());
  438. base_type::push_record_unlocked(boost::move(rec));
  439. }
  440. /*!
  441. * Thread-safe implementation of swap
  442. */
  443. void swap(basic_composite_logger& that)
  444. {
  445. boost::log::aux::multiple_unique_lock2<
  446. threading_model,
  447. threading_model
  448. > lock(base_type::get_threading_model(), that.get_threading_model());
  449. base_type::swap_unlocked(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) :
  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(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) : 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_