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