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/sinks/basic_sink_backend.hpp>
22 #include <boost/log/sinks/frontend_requirements.hpp>
23 #include <boost/log/detail/header.hpp>
25 #ifdef BOOST_HAS_PRAGMA_ONCE
31 BOOST_LOG_OPEN_NAMESPACE
36 * \brief An implementation of a text output stream logging sink backend
38 * The sink backend puts formatted log records to one or more text streams.
40 template< typename CharT >
41 class basic_text_ostream_backend :
42 public basic_formatted_sink_backend<
44 combine_requirements< synchronized_feeding, flushing >::type
48 typedef basic_formatted_sink_backend<
50 combine_requirements< synchronized_feeding, flushing >::type
55 typedef typename base_type::char_type char_type;
56 //! String type to be used as a message text holder
57 typedef typename base_type::string_type string_type;
58 //! Output stream type
59 typedef std::basic_ostream< char_type > stream_type;
64 struct implementation;
65 implementation* m_pImpl;
71 * Constructor. No streams attached to the constructed backend, auto flush feature disabled.
73 BOOST_LOG_API basic_text_ostream_backend();
77 BOOST_LOG_API ~basic_text_ostream_backend();
80 * The method adds a new stream to the sink.
82 * \param strm Pointer to the stream. Must not be NULL.
84 BOOST_LOG_API void add_stream(shared_ptr< stream_type > const& strm);
86 * The method removes a stream from the sink. If the stream is not attached to the sink,
87 * the method has no effect.
89 * \param strm Pointer to the stream. Must not be NULL.
91 BOOST_LOG_API void remove_stream(shared_ptr< stream_type > const& strm);
94 * Sets the flag to automatically flush buffers of all attached streams after each log record
96 BOOST_LOG_API void auto_flush(bool f = true);
99 * The method writes the message to the sink
101 BOOST_LOG_API void consume(record_view const& rec, string_type const& formatted_message);
104 * The method flushes the associated streams
106 BOOST_LOG_API void flush();
109 #ifdef BOOST_LOG_USE_CHAR
110 typedef basic_text_ostream_backend< char > text_ostream_backend; //!< Convenience typedef for narrow-character logging
112 #ifdef BOOST_LOG_USE_WCHAR_T
113 typedef basic_text_ostream_backend< wchar_t > wtext_ostream_backend; //!< Convenience typedef for wide-character logging
118 BOOST_LOG_CLOSE_NAMESPACE // namespace log
122 #include <boost/log/detail/footer.hpp>
124 #endif // BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_