channel_logger.hpp 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 channel_logger.hpp
  9. * \author Andrey Semashev
  10. * \date 28.02.2008
  11. *
  12. * The header contains implementation of a logger with channel support.
  13. */
  14. #ifndef BOOST_LOG_SOURCES_CHANNEL_LOGGER_HPP_INCLUDED_
  15. #define BOOST_LOG_SOURCES_CHANNEL_LOGGER_HPP_INCLUDED_
  16. #include <boost/log/detail/config.hpp>
  17. #if !defined(BOOST_LOG_NO_THREADS)
  18. #include <boost/log/detail/light_rw_mutex.hpp>
  19. #endif // !defined(BOOST_LOG_NO_THREADS)
  20. #include <boost/log/sources/features.hpp>
  21. #include <boost/log/sources/basic_logger.hpp>
  22. #include <boost/log/sources/threading_models.hpp>
  23. #include <boost/log/sources/channel_feature.hpp>
  24. #include <boost/log/keywords/channel.hpp>
  25. #include <boost/log/detail/header.hpp>
  26. #ifdef BOOST_HAS_PRAGMA_ONCE
  27. #pragma once
  28. #endif
  29. namespace boost {
  30. BOOST_LOG_OPEN_NAMESPACE
  31. namespace sources {
  32. #ifndef BOOST_LOG_DOXYGEN_PASS
  33. #ifdef BOOST_LOG_USE_CHAR
  34. //! Narrow-char logger with channel support
  35. template< typename ChannelT = std::string >
  36. class channel_logger :
  37. public basic_composite_logger<
  38. char,
  39. channel_logger< ChannelT >,
  40. single_thread_model,
  41. features< channel< ChannelT > >
  42. >
  43. {
  44. typedef typename channel_logger::logger_base base_type;
  45. public:
  46. BOOST_LOG_FORWARD_LOGGER_MEMBERS_TEMPLATE(channel_logger)
  47. explicit channel_logger(ChannelT const& channel) : base_type(keywords::channel = channel)
  48. {
  49. }
  50. };
  51. #if !defined(BOOST_LOG_NO_THREADS)
  52. //! Narrow-char thread-safe logger with channel support
  53. template< typename ChannelT = std::string >
  54. class channel_logger_mt :
  55. public basic_composite_logger<
  56. char,
  57. channel_logger_mt< ChannelT >,
  58. multi_thread_model< boost::log::aux::light_rw_mutex >,
  59. features< channel< ChannelT > >
  60. >
  61. {
  62. typedef typename channel_logger_mt::logger_base base_type;
  63. public:
  64. BOOST_LOG_FORWARD_LOGGER_MEMBERS_TEMPLATE(channel_logger_mt)
  65. explicit channel_logger_mt(ChannelT const& channel) : base_type(keywords::channel = channel)
  66. {
  67. }
  68. };
  69. #endif // !defined(BOOST_LOG_NO_THREADS)
  70. #endif // BOOST_LOG_USE_CHAR
  71. #ifdef BOOST_LOG_USE_WCHAR_T
  72. //! Wide-char logger with channel support
  73. template< typename ChannelT = std::wstring >
  74. class wchannel_logger :
  75. public basic_composite_logger<
  76. wchar_t,
  77. wchannel_logger< ChannelT >,
  78. single_thread_model,
  79. features< channel< ChannelT > >
  80. >
  81. {
  82. typedef typename wchannel_logger::logger_base base_type;
  83. public:
  84. BOOST_LOG_FORWARD_LOGGER_MEMBERS_TEMPLATE(wchannel_logger)
  85. explicit wchannel_logger(ChannelT const& channel) : base_type(keywords::channel = channel)
  86. {
  87. }
  88. };
  89. #if !defined(BOOST_LOG_NO_THREADS)
  90. //! Wide-char thread-safe logger with channel support
  91. template< typename ChannelT = std::wstring >
  92. class wchannel_logger_mt :
  93. public basic_composite_logger<
  94. wchar_t,
  95. wchannel_logger< ChannelT >,
  96. multi_thread_model< boost::log::aux::light_rw_mutex >,
  97. features< channel< ChannelT > >
  98. >
  99. {
  100. typedef typename wchannel_logger_mt::logger_base base_type;
  101. public:
  102. BOOST_LOG_FORWARD_LOGGER_MEMBERS_TEMPLATE(wchannel_logger_mt)
  103. explicit wchannel_logger_mt(ChannelT const& channel) : base_type(keywords::channel = channel)
  104. {
  105. }
  106. };
  107. #endif // !defined(BOOST_LOG_NO_THREADS)
  108. #endif // BOOST_LOG_USE_WCHAR_T
  109. #else // BOOST_LOG_DOXYGEN_PASS
  110. /*!
  111. * \brief Narrow-char logger. Functionally equivalent to \c basic_channel_logger.
  112. *
  113. * See \c channel class template for a more detailed description
  114. */
  115. template< typename ChannelT = std::string >
  116. class channel_logger :
  117. public basic_composite_logger<
  118. char,
  119. channel_logger< ChannelT >,
  120. single_thread_model,
  121. features< channel< ChannelT > >
  122. >
  123. {
  124. public:
  125. /*!
  126. * Default constructor
  127. */
  128. channel_logger();
  129. /*!
  130. * Copy constructor
  131. */
  132. channel_logger(channel_logger const& that);
  133. /*!
  134. * Constructor with named arguments
  135. */
  136. template< typename... ArgsT >
  137. explicit channel_logger(ArgsT... const& args);
  138. /*!
  139. * The constructor creates the logger with the specified channel name
  140. *
  141. * \param channel The channel name
  142. */
  143. explicit channel_logger(ChannelT const& channel);
  144. /*!
  145. * Assignment operator
  146. */
  147. channel_logger& operator= (channel_logger const& that)
  148. /*!
  149. * Swaps two loggers
  150. */
  151. void swap(channel_logger& that);
  152. };
  153. /*!
  154. * \brief Narrow-char thread-safe logger. Functionally equivalent to \c basic_channel_logger.
  155. *
  156. * See \c channel class template for a more detailed description
  157. */
  158. template< typename ChannelT = std::string >
  159. class channel_logger_mt :
  160. public basic_composite_logger<
  161. char,
  162. channel_logger_mt< ChannelT >,
  163. multi_thread_model< implementation_defined >,
  164. features< channel< ChannelT > >
  165. >
  166. {
  167. public:
  168. /*!
  169. * Default constructor
  170. */
  171. channel_logger_mt();
  172. /*!
  173. * Copy constructor
  174. */
  175. channel_logger_mt(channel_logger_mt const& that);
  176. /*!
  177. * Constructor with named arguments
  178. */
  179. template< typename... ArgsT >
  180. explicit channel_logger_mt(ArgsT... const& args);
  181. /*!
  182. * The constructor creates the logger with the specified channel name
  183. *
  184. * \param channel The channel name
  185. */
  186. explicit channel_logger_mt(ChannelT const& channel);
  187. /*!
  188. * Assignment operator
  189. */
  190. channel_logger_mt& operator= (channel_logger_mt const& that)
  191. /*!
  192. * Swaps two loggers
  193. */
  194. void swap(channel_logger_mt& that);
  195. };
  196. /*!
  197. * \brief Wide-char logger. Functionally equivalent to \c basic_channel_logger.
  198. *
  199. * See \c channel class template for a more detailed description
  200. */
  201. template< typename ChannelT = std::wstring >
  202. class wchannel_logger :
  203. public basic_composite_logger<
  204. wchar_t,
  205. wchannel_logger< ChannelT >,
  206. single_thread_model,
  207. features< channel< ChannelT > >
  208. >
  209. {
  210. public:
  211. /*!
  212. * Default constructor
  213. */
  214. wchannel_logger();
  215. /*!
  216. * Copy constructor
  217. */
  218. wchannel_logger(wchannel_logger const& that);
  219. /*!
  220. * Constructor with named arguments
  221. */
  222. template< typename... ArgsT >
  223. explicit wchannel_logger(ArgsT... const& args);
  224. /*!
  225. * The constructor creates the logger with the specified channel name
  226. *
  227. * \param channel The channel name
  228. */
  229. explicit wchannel_logger(ChannelT const& channel);
  230. /*!
  231. * Assignment operator
  232. */
  233. wchannel_logger& operator= (wchannel_logger const& that)
  234. /*!
  235. * Swaps two loggers
  236. */
  237. void swap(wchannel_logger& that);
  238. };
  239. /*!
  240. * \brief Wide-char thread-safe logger. Functionally equivalent to \c basic_channel_logger.
  241. *
  242. * See \c channel class template for a more detailed description
  243. */
  244. template< typename ChannelT = std::wstring >
  245. class wchannel_logger_mt :
  246. public basic_composite_logger<
  247. wchar_t,
  248. wchannel_logger< ChannelT >,
  249. multi_thread_model< implementation_defined >,
  250. features< channel< ChannelT > >
  251. >
  252. {
  253. public:
  254. /*!
  255. * Default constructor
  256. */
  257. wchannel_logger_mt();
  258. /*!
  259. * Copy constructor
  260. */
  261. wchannel_logger_mt(wchannel_logger_mt const& that);
  262. /*!
  263. * Constructor with named arguments
  264. */
  265. template< typename... ArgsT >
  266. explicit wchannel_logger_mt(ArgsT... const& args);
  267. /*!
  268. * The constructor creates the logger with the specified channel name
  269. *
  270. * \param channel The channel name
  271. */
  272. explicit wchannel_logger_mt(ChannelT const& channel);
  273. /*!
  274. * Assignment operator
  275. */
  276. wchannel_logger_mt& operator= (wchannel_logger_mt const& that)
  277. /*!
  278. * Swaps two loggers
  279. */
  280. void swap(wchannel_logger_mt& that);
  281. };
  282. #endif // BOOST_LOG_DOXYGEN_PASS
  283. } // namespace sources
  284. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  285. } // namespace boost
  286. #include <boost/log/detail/footer.hpp>
  287. #endif // BOOST_LOG_SOURCES_CHANNEL_LOGGER_HPP_INCLUDED_