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_FILE_HPP_INCLUDED_
0016 #define BOOST_LOG_UTILITY_SETUP_FILE_HPP_INCLUDED_
0017
0018 #include <boost/type_traits/is_void.hpp>
0019 #include <boost/type_traits/integral_constant.hpp>
0020 #include <boost/smart_ptr/shared_ptr.hpp>
0021 #include <boost/smart_ptr/make_shared_object.hpp>
0022 #include <boost/parameter/parameters.hpp> // for is_named_argument
0023 #include <boost/preprocessor/control/expr_if.hpp>
0024 #include <boost/preprocessor/comparison/greater.hpp>
0025 #include <boost/preprocessor/punctuation/comma_if.hpp>
0026 #include <boost/preprocessor/repetition/enum_params.hpp>
0027 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
0028 #include <boost/preprocessor/repetition/enum_shifted_params.hpp>
0029 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
0030 #include <boost/log/detail/config.hpp>
0031 #include <boost/log/detail/sink_init_helpers.hpp>
0032 #include <boost/log/detail/parameter_tools.hpp>
0033 #include <boost/log/core/core.hpp>
0034 #ifndef BOOST_LOG_NO_THREADS
0035 #include <boost/log/sinks/sync_frontend.hpp>
0036 #else
0037 #include <boost/log/sinks/unlocked_frontend.hpp>
0038 #endif
0039 #include <boost/log/sinks/text_file_backend.hpp>
0040 #include <boost/log/keywords/format.hpp>
0041 #include <boost/log/keywords/filter.hpp>
0042 #include <boost/log/keywords/scan_method.hpp>
0043 #include <boost/log/detail/header.hpp>
0044
0045 #ifdef BOOST_HAS_PRAGMA_ONCE
0046 #pragma once
0047 #endif
0048
0049 #ifndef BOOST_LOG_DOXYGEN_PASS
0050 #ifndef BOOST_LOG_NO_THREADS
0051 #define BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL sinks::synchronous_sink
0052 #else
0053 #define BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL sinks::unlocked_sink
0054 #endif
0055 #endif
0056
0057 namespace boost {
0058
0059 BOOST_LOG_OPEN_NAMESPACE
0060
0061 namespace aux {
0062
0063
0064 template< typename ArgsT >
0065 inline shared_ptr< sinks::file::collector > setup_file_collector(ArgsT const&, boost::true_type)
0066 {
0067 return shared_ptr< sinks::file::collector >();
0068 }
0069 template< typename ArgsT >
0070 inline shared_ptr< sinks::file::collector > setup_file_collector(ArgsT const& args, boost::false_type)
0071 {
0072 return sinks::file::make_collector(args);
0073 }
0074
0075
0076 template< typename ArgsT >
0077 shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< sinks::text_file_backend > > add_file_log(ArgsT const& args)
0078 {
0079 typedef sinks::text_file_backend backend_t;
0080 shared_ptr< backend_t > pBackend = boost::make_shared< backend_t >(args);
0081
0082 shared_ptr< sinks::file::collector > pCollector = aux::setup_file_collector(args,
0083 typename is_void< typename parameter::binding< ArgsT, keywords::tag::target, void >::type >::type());
0084 if (pCollector)
0085 {
0086 pBackend->set_file_collector(pCollector);
0087 pBackend->scan_for_files(args[keywords::scan_method | sinks::file::scan_matching]);
0088 }
0089
0090 shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< backend_t > > pSink =
0091 boost::make_shared< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< backend_t > >(pBackend);
0092
0093 aux::setup_filter(*pSink, args,
0094 typename is_void< typename parameter::binding< ArgsT, keywords::tag::filter, void >::type >::type());
0095
0096 aux::setup_formatter(*pSink, args,
0097 typename is_void< typename parameter::binding< ArgsT, keywords::tag::format, void >::type >::type());
0098
0099 core::get()->add_sink(pSink);
0100
0101 return pSink;
0102 }
0103
0104
0105 template< typename T, bool IsNamedArgument = parameter::aux::is_named_argument< T >::value >
0106 struct file_name_param_traits
0107 {
0108 static shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< sinks::text_file_backend > > wrap_add_file_log(T const& file_name_arg)
0109 {
0110 return aux::add_file_log(file_name_arg);
0111 }
0112
0113 template< typename ArgsT >
0114 static shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< sinks::text_file_backend > > wrap_add_file_log(T const& file_name_arg, ArgsT const& args)
0115 {
0116 return aux::add_file_log((args, file_name_arg));
0117 }
0118 };
0119
0120 template< typename T >
0121 struct file_name_param_traits< T, false >
0122 {
0123 static shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< sinks::text_file_backend > > wrap_add_file_log(T const& file_name_arg)
0124 {
0125 return aux::add_file_log(keywords::file_name = file_name_arg);
0126 }
0127
0128 template< typename ArgsT >
0129 static shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< sinks::text_file_backend > > wrap_add_file_log(T const& file_name_arg, ArgsT const& args)
0130 {
0131 return aux::add_file_log((args, (keywords::file_name = file_name_arg)));
0132 }
0133 };
0134
0135 }
0136
0137 #ifndef BOOST_LOG_DOXYGEN_PASS
0138
0139 #define BOOST_LOG_INIT_LOG_TO_FILE_INTERNAL(z, n, data)\
0140 template< BOOST_PP_ENUM_PARAMS_Z(z, n, typename T) >\
0141 inline shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< sinks::text_file_backend > > add_file_log(BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, T, const& arg))\
0142 {\
0143 return aux::file_name_param_traits< T0 >::wrap_add_file_log(\
0144 arg0\
0145 BOOST_PP_COMMA_IF(BOOST_PP_GREATER(n, 1))\
0146 BOOST_PP_EXPR_IF(BOOST_PP_GREATER(n, 1), (BOOST_PP_ENUM_SHIFTED_PARAMS_Z(z, n, arg)))\
0147 );\
0148 }
0149
0150 BOOST_PP_REPEAT_FROM_TO(1, BOOST_LOG_MAX_PARAMETER_ARGS, BOOST_LOG_INIT_LOG_TO_FILE_INTERNAL, ~)
0151
0152 #undef BOOST_LOG_INIT_LOG_TO_FILE_INTERNAL
0153
0154 #else
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 template< typename... ArgsT >
0189 shared_ptr< BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL< sinks::text_file_backend > > add_file_log(ArgsT... const& args);
0190
0191 #endif
0192
0193 BOOST_LOG_CLOSE_NAMESPACE
0194
0195 }
0196
0197 #undef BOOST_LOG_FILE_SINK_FRONTEND_INTERNAL
0198
0199 #include <boost/log/detail/footer.hpp>
0200
0201 #endif