File indexing completed on 2025-01-18 09:39:25
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_LOG_SINKS_TEXT_MULTIFILE_BACKEND_HPP_INCLUDED_
0016 #define BOOST_LOG_SINKS_TEXT_MULTIFILE_BACKEND_HPP_INCLUDED_
0017
0018 #include <ios>
0019 #include <string>
0020 #include <locale>
0021 #include <ostream>
0022 #include <boost/mpl/if.hpp>
0023 #include <boost/mpl/bool.hpp>
0024 #include <boost/type_traits/is_same.hpp>
0025 #include <boost/filesystem/path.hpp>
0026 #include <boost/log/detail/config.hpp>
0027 #include <boost/log/detail/light_function.hpp>
0028 #include <boost/log/detail/parameter_tools.hpp>
0029 #include <boost/log/detail/cleanup_scope_guard.hpp>
0030 #include <boost/log/keywords/auto_newline_mode.hpp>
0031 #include <boost/log/sinks/auto_newline_mode.hpp>
0032 #include <boost/log/sinks/basic_sink_backend.hpp>
0033 #include <boost/log/utility/formatting_ostream.hpp>
0034 #include <boost/log/detail/header.hpp>
0035
0036 #ifdef BOOST_HAS_PRAGMA_ONCE
0037 #pragma once
0038 #endif
0039
0040 namespace boost {
0041
0042 BOOST_LOG_OPEN_NAMESPACE
0043
0044 namespace sinks {
0045
0046 namespace file {
0047
0048
0049
0050
0051 template< typename FormatterT >
0052 class file_name_composer_adapter
0053 {
0054 public:
0055
0056 typedef filesystem::path result_type;
0057
0058 typedef result_type::string_type::value_type native_char_type;
0059
0060 typedef FormatterT formatter_type;
0061
0062 typedef basic_formatting_ostream< native_char_type > stream_type;
0063
0064 private:
0065
0066 formatter_type m_Formatter;
0067
0068 mutable result_type::string_type m_FileName;
0069
0070 mutable stream_type m_FormattingStream;
0071
0072 public:
0073
0074
0075
0076 explicit file_name_composer_adapter(formatter_type const& formatter, std::locale const& loc = std::locale()) :
0077 m_Formatter(formatter),
0078 m_FormattingStream(m_FileName)
0079 {
0080 m_FormattingStream.exceptions(std::ios_base::badbit | std::ios_base::failbit);
0081 m_FormattingStream.imbue(loc);
0082 }
0083
0084
0085
0086 file_name_composer_adapter(file_name_composer_adapter const& that) :
0087 m_Formatter(that.m_Formatter),
0088 m_FormattingStream(m_FileName)
0089 {
0090 m_FormattingStream.exceptions(std::ios_base::badbit | std::ios_base::failbit);
0091 m_FormattingStream.imbue(that.m_FormattingStream.getloc());
0092 }
0093
0094
0095
0096 file_name_composer_adapter& operator= (file_name_composer_adapter const& that)
0097 {
0098 m_Formatter = that.m_Formatter;
0099 return *this;
0100 }
0101
0102
0103
0104
0105 result_type operator() (record_view const& rec) const
0106 {
0107 boost::log::aux::cleanup_guard< stream_type > cleanup1(m_FormattingStream);
0108 boost::log::aux::cleanup_guard< result_type::string_type > cleanup2(m_FileName);
0109
0110 m_Formatter(rec, m_FormattingStream);
0111 m_FormattingStream.flush();
0112
0113 return result_type(m_FileName);
0114 }
0115 };
0116
0117
0118
0119
0120
0121
0122
0123 template< typename FormatterT >
0124 inline file_name_composer_adapter< FormatterT > as_file_name_composer(
0125 FormatterT const& fmt, std::locale const& loc = std::locale())
0126 {
0127 return file_name_composer_adapter< FormatterT >(fmt, loc);
0128 }
0129
0130 }
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141 class text_multifile_backend :
0142 public basic_formatted_sink_backend< char >
0143 {
0144
0145 typedef basic_formatted_sink_backend< char > base_type;
0146
0147 public:
0148
0149 typedef base_type::char_type char_type;
0150
0151 typedef base_type::string_type string_type;
0152
0153
0154 typedef boost::log::aux::light_function< filesystem::path (record_view const&) > file_name_composer_type;
0155
0156 private:
0157
0158
0159 struct implementation;
0160 implementation* m_pImpl;
0161
0162
0163
0164 public:
0165
0166
0167
0168
0169 BOOST_LOG_API text_multifile_backend();
0170
0171
0172
0173
0174
0175
0176
0177
0178 #ifndef BOOST_LOG_DOXYGEN_PASS
0179 BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_CALL(text_multifile_backend, construct)
0180 #else
0181 template< typename... ArgsT >
0182 explicit text_multifile_backend(ArgsT... const& args);
0183 #endif
0184
0185
0186
0187
0188 BOOST_LOG_API ~text_multifile_backend();
0189
0190
0191
0192
0193
0194
0195 template< typename ComposerT >
0196 void set_file_name_composer(ComposerT const& composer)
0197 {
0198 set_file_name_composer_internal(composer);
0199 }
0200
0201
0202
0203
0204
0205
0206
0207 BOOST_LOG_API void set_auto_newline_mode(auto_newline_mode mode);
0208
0209
0210
0211
0212 BOOST_LOG_API void consume(record_view const& rec, string_type const& formatted_message);
0213
0214 private:
0215 #ifndef BOOST_LOG_DOXYGEN_PASS
0216
0217 template< typename ArgsT >
0218 void construct(ArgsT const& args)
0219 {
0220 construct(args[keywords::auto_newline_mode | insert_if_missing]);
0221 }
0222
0223 BOOST_LOG_API void construct(auto_newline_mode auto_newline);
0224
0225
0226 BOOST_LOG_API void set_file_name_composer_internal(file_name_composer_type const& composer);
0227 #endif
0228 };
0229
0230 }
0231
0232 BOOST_LOG_CLOSE_NAMESPACE
0233
0234 }
0235
0236 #include <boost/log/detail/footer.hpp>
0237
0238 #endif