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