File indexing completed on 2025-01-18 09:39:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_LOG_UTILITY_SETUP_CONSOLE_HPP_INCLUDED_
0016 #define BOOST_LOG_UTILITY_SETUP_CONSOLE_HPP_INCLUDED_
0017
0018 #include <iostream>
0019 #include <boost/type_traits/is_void.hpp>
0020 #include <boost/smart_ptr/shared_ptr.hpp>
0021 #include <boost/smart_ptr/make_shared_object.hpp>
0022 #include <boost/core/null_deleter.hpp>
0023 #include <boost/log/detail/config.hpp>
0024 #include <boost/log/detail/parameter_tools.hpp>
0025 #include <boost/log/detail/sink_init_helpers.hpp>
0026 #ifndef BOOST_LOG_NO_THREADS
0027 #include <boost/log/sinks/sync_frontend.hpp>
0028 #else
0029 #include <boost/log/sinks/unlocked_frontend.hpp>
0030 #endif
0031 #include <boost/log/sinks/text_ostream_backend.hpp>
0032 #include <boost/log/keywords/format.hpp>
0033 #include <boost/log/keywords/filter.hpp>
0034 #include <boost/log/detail/header.hpp>
0035
0036 #ifdef BOOST_HAS_PRAGMA_ONCE
0037 #pragma once
0038 #endif
0039
0040
0041 #ifndef BOOST_LOG_DOXYGEN_PASS
0042 #ifndef BOOST_LOG_NO_THREADS
0043 #define BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL sinks::synchronous_sink
0044 #else
0045 #define BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL sinks::unlocked_sink
0046 #endif
0047 #endif
0048
0049 namespace boost {
0050
0051 BOOST_LOG_OPEN_NAMESPACE
0052
0053 namespace aux {
0054
0055
0056 template< typename CharT, typename ArgsT >
0057 shared_ptr<
0058 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0059 sinks::basic_text_ostream_backend< CharT >
0060 >
0061 > add_console_log(std::basic_ostream< CharT >& strm, ArgsT const& args)
0062 {
0063 shared_ptr< std::basic_ostream< CharT > > pStream(&strm, boost::null_deleter());
0064
0065 typedef sinks::basic_text_ostream_backend< CharT > backend_t;
0066 shared_ptr< backend_t > pBackend = boost::make_shared< backend_t >(args);
0067
0068 pBackend->add_stream(pStream);
0069
0070 typedef BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL< backend_t > sink_t;
0071 shared_ptr< sink_t > pSink = boost::make_shared< sink_t >(pBackend);
0072
0073 aux::setup_filter(*pSink, args,
0074 typename is_void< typename parameter::binding< ArgsT, keywords::tag::filter, void >::type >::type());
0075
0076 aux::setup_formatter(*pSink, args,
0077 typename is_void< typename parameter::binding< ArgsT, keywords::tag::format, void >::type >::type());
0078
0079 core::get()->add_sink(pSink);
0080
0081 return pSink;
0082 }
0083
0084 template< typename CharT >
0085 struct default_console_stream;
0086
0087 #ifdef BOOST_LOG_USE_CHAR
0088 template< >
0089 struct default_console_stream< char >
0090 {
0091 static std::ostream& get() { return std::clog; }
0092 };
0093 #endif
0094
0095 #ifdef BOOST_LOG_USE_WCHAR_T
0096 template< >
0097 struct default_console_stream< wchar_t >
0098 {
0099 static std::wostream& get() { return std::wclog; }
0100 };
0101 #endif
0102
0103 }
0104
0105 #ifndef BOOST_LOG_DOXYGEN_PASS
0106
0107 template< typename CharT >
0108 inline shared_ptr<
0109 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0110 sinks::basic_text_ostream_backend< CharT >
0111 >
0112 > add_console_log()
0113 {
0114 return aux::add_console_log(
0115 aux::default_console_stream< CharT >::get(), log::aux::empty_arg_list());
0116 }
0117
0118
0119 template< typename CharT >
0120 inline shared_ptr<
0121 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0122 sinks::basic_text_ostream_backend< CharT >
0123 >
0124 > add_console_log(std::basic_ostream< CharT >& strm)
0125 {
0126 return aux::add_console_log(strm, log::aux::empty_arg_list());
0127 }
0128
0129 template< typename CharT, typename ArgT1 >
0130 inline shared_ptr<
0131 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0132 sinks::basic_text_ostream_backend< CharT >
0133 >
0134 > add_console_log(std::basic_ostream< CharT >& strm, ArgT1 const& arg1)
0135 {
0136 return aux::add_console_log(strm, arg1);
0137 }
0138
0139 template< typename CharT, typename ArgT1, typename ArgT2 >
0140 inline shared_ptr<
0141 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0142 sinks::basic_text_ostream_backend< CharT >
0143 >
0144 > add_console_log(std::basic_ostream< CharT >& strm, ArgT1 const& arg1, ArgT2 const& arg2)
0145 {
0146 return aux::add_console_log(strm, (arg1, arg2));
0147 }
0148
0149 template< typename CharT, typename ArgT1, typename ArgT2, typename ArgT3 >
0150 inline shared_ptr<
0151 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0152 sinks::basic_text_ostream_backend< CharT >
0153 >
0154 > add_console_log(std::basic_ostream< CharT >& strm, ArgT1 const& arg1, ArgT2 const& arg2, ArgT3 const& arg3)
0155 {
0156 return aux::add_console_log(strm, (arg1, arg2, arg3));
0157 }
0158
0159 template< typename CharT, typename ArgT1, typename ArgT2, typename ArgT3, typename ArgT4 >
0160 inline shared_ptr<
0161 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0162 sinks::basic_text_ostream_backend< CharT >
0163 >
0164 > add_console_log(std::basic_ostream< CharT >& strm, ArgT1 const& arg1, ArgT2 const& arg2, ArgT3 const& arg3, ArgT3 const& arg4)
0165 {
0166 return aux::add_console_log(strm, (arg1, arg2, arg3, arg4));
0167 }
0168
0169 #else
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187 template< typename CharT, typename... ArgsT >
0188 shared_ptr<
0189 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0190 sinks::basic_text_ostream_backend< CharT >
0191 >
0192 > add_console_log(std::basic_ostream< CharT >& strm, ArgsT... const& args);
0193
0194
0195
0196
0197
0198
0199
0200 template< typename CharT, typename... ArgsT >
0201 shared_ptr<
0202 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0203 sinks::basic_text_ostream_backend< CharT >
0204 >
0205 > add_console_log(ArgsT... const& args);
0206
0207 #endif
0208
0209 #ifdef BOOST_LOG_USE_CHAR
0210
0211
0212
0213
0214
0215
0216
0217
0218 inline shared_ptr<
0219 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0220 sinks::text_ostream_backend
0221 >
0222 > add_console_log()
0223 {
0224 return add_console_log(std::clog);
0225 }
0226
0227 #endif
0228
0229 #ifdef BOOST_LOG_USE_WCHAR_T
0230
0231
0232
0233
0234
0235
0236 inline shared_ptr<
0237 BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL<
0238 sinks::wtext_ostream_backend
0239 >
0240 > wadd_console_log()
0241 {
0242 return add_console_log(std::wclog);
0243 }
0244
0245 #endif
0246
0247 BOOST_LOG_CLOSE_NAMESPACE
0248
0249 }
0250
0251 #undef BOOST_LOG_CONSOLE_SINK_FRONTEND_INTERNAL
0252
0253 #include <boost/log/detail/footer.hpp>
0254
0255 #endif