severity_channel_logger.hpp 8.5 KB

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