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)
8 * \file text_ostream_backend.hpp
9 * \author Andrey Semashev
12 * The header contains implementation of a text output stream sink backend.
15 #ifndef BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_
16 #define BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_
19 #include <boost/smart_ptr/shared_ptr.hpp>
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/detail/parameter_tools.hpp>
22 #include <boost/log/keywords/auto_flush.hpp>
23 #include <boost/log/keywords/auto_newline_mode.hpp>
24 #include <boost/log/sinks/auto_newline_mode.hpp>
25 #include <boost/log/sinks/basic_sink_backend.hpp>
26 #include <boost/log/sinks/frontend_requirements.hpp>
27 #include <boost/log/detail/header.hpp>
29 #ifdef BOOST_HAS_PRAGMA_ONCE
35 BOOST_LOG_OPEN_NAMESPACE
40 * \brief An implementation of a text output stream logging sink backend
42 * The sink backend puts formatted log records to one or more text streams.
44 template< typename CharT >
45 class basic_text_ostream_backend :
46 public basic_formatted_sink_backend<
48 combine_requirements< synchronized_feeding, flushing >::type
52 typedef basic_formatted_sink_backend<
54 combine_requirements< synchronized_feeding, flushing >::type
59 typedef typename base_type::char_type char_type;
60 //! String type to be used as a message text holder
61 typedef typename base_type::string_type string_type;
62 //! Output stream type
63 typedef std::basic_ostream< char_type > stream_type;
68 struct implementation;
69 implementation* m_pImpl;
75 * Constructor. No streams attached to the constructed backend, auto flush feature disabled.
77 BOOST_LOG_API basic_text_ostream_backend();
80 * Constructor. Creates a sink backend with the specified named parameters.
81 * The following named parameters are supported:
83 * \li \c auto_flush - Specifies a flag, whether or not to automatically flush the attached streams after each
84 * written log record. By default, is \c false.
85 * \li \c auto_newline_mode - Specifies automatic trailing newline insertion mode. Must be a value of
86 * the \c auto_newline_mode enum. By default, is <tt>auto_newline_mode::insert_if_missing</tt>.
88 #ifndef BOOST_LOG_DOXYGEN_PASS
89 BOOST_LOG_PARAMETRIZED_CONSTRUCTORS_CALL(basic_text_ostream_backend, construct)
91 template< typename... ArgsT >
92 explicit basic_text_ostream_backend(ArgsT... const& args);
98 BOOST_LOG_API ~basic_text_ostream_backend();
101 * The method adds a new stream to the sink.
103 * \param strm Pointer to the stream. Must not be NULL.
105 BOOST_LOG_API void add_stream(shared_ptr< stream_type > const& strm);
107 * The method removes a stream from the sink. If the stream is not attached to the sink,
108 * the method has no effect.
110 * \param strm Pointer to the stream. Must not be NULL.
112 BOOST_LOG_API void remove_stream(shared_ptr< stream_type > const& strm);
115 * Sets the flag to automatically flush buffers of all attached streams after each log record.
117 * \param enable The flag indicates whether the automatic buffer flush should be performed.
119 BOOST_LOG_API void auto_flush(bool enable = true);
122 * Selects whether a trailing newline should be automatically inserted after every log record. See
123 * \c auto_newline_mode description for the possible modes of operation.
125 * \param mode The trailing newline insertion mode.
127 BOOST_LOG_API void set_auto_newline_mode(auto_newline_mode mode);
130 * The method writes the message to the sink.
132 BOOST_LOG_API void consume(record_view const& rec, string_type const& formatted_message);
135 * The method flushes all attached streams.
137 BOOST_LOG_API void flush();
140 #ifndef BOOST_LOG_DOXYGEN_PASS
141 //! Constructor implementation
142 template< typename ArgsT >
143 void construct(ArgsT const& args)
146 args[keywords::auto_newline_mode | insert_if_missing],
147 args[keywords::auto_flush | false]);
149 //! Constructor implementation
150 BOOST_LOG_API void construct(auto_newline_mode auto_newline, bool auto_flush);
151 #endif // BOOST_LOG_DOXYGEN_PASS
154 #ifdef BOOST_LOG_USE_CHAR
155 typedef basic_text_ostream_backend< char > text_ostream_backend; //!< Convenience typedef for narrow-character logging
157 #ifdef BOOST_LOG_USE_WCHAR_T
158 typedef basic_text_ostream_backend< wchar_t > wtext_ostream_backend; //!< Convenience typedef for wide-character logging
163 BOOST_LOG_CLOSE_NAMESPACE // namespace log
167 #include <boost/log/detail/footer.hpp>
169 #endif // BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_