Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file text_ostream_backend.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 22.04.2007 Chris@16: * Chris@16: * The header contains implementation of a text output stream sink backend. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: namespace sinks { Chris@16: Chris@16: /*! Chris@16: * \brief An implementation of a text output stream logging sink backend Chris@16: * Chris@16: * The sink backend puts formatted log records to one or more text streams. Chris@16: */ Chris@16: template< typename CharT > Chris@16: class basic_text_ostream_backend : Chris@16: public basic_formatted_sink_backend< Chris@16: CharT, Chris@16: combine_requirements< synchronized_feeding, flushing >::type Chris@16: > Chris@16: { Chris@16: //! Base type Chris@16: typedef basic_formatted_sink_backend< Chris@16: CharT, Chris@16: combine_requirements< synchronized_feeding, flushing >::type Chris@16: > base_type; Chris@16: Chris@16: public: Chris@16: //! Character type Chris@16: typedef typename base_type::char_type char_type; Chris@16: //! String type to be used as a message text holder Chris@16: typedef typename base_type::string_type string_type; Chris@16: //! Output stream type Chris@16: typedef std::basic_ostream< char_type > stream_type; Chris@16: Chris@16: private: Chris@16: //! \cond Chris@16: Chris@16: struct implementation; Chris@16: implementation* m_pImpl; Chris@16: Chris@16: //! \endcond Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Constructor. No streams attached to the constructed backend, auto flush feature disabled. Chris@16: */ Chris@16: BOOST_LOG_API basic_text_ostream_backend(); Chris@16: /*! Chris@16: * Destructor Chris@16: */ Chris@16: BOOST_LOG_API ~basic_text_ostream_backend(); Chris@16: Chris@16: /*! Chris@16: * The method adds a new stream to the sink. Chris@16: * Chris@16: * \param strm Pointer to the stream. Must not be NULL. Chris@16: */ Chris@16: BOOST_LOG_API void add_stream(shared_ptr< stream_type > const& strm); Chris@16: /*! Chris@16: * The method removes a stream from the sink. If the stream is not attached to the sink, Chris@16: * the method has no effect. Chris@16: * Chris@16: * \param strm Pointer to the stream. Must not be NULL. Chris@16: */ Chris@16: BOOST_LOG_API void remove_stream(shared_ptr< stream_type > const& strm); Chris@16: Chris@16: /*! Chris@16: * Sets the flag to automatically flush buffers of all attached streams after each log record Chris@16: */ Chris@16: BOOST_LOG_API void auto_flush(bool f = true); Chris@16: Chris@16: /*! Chris@16: * The method writes the message to the sink Chris@16: */ Chris@16: BOOST_LOG_API void consume(record_view const& rec, string_type const& formatted_message); Chris@16: Chris@16: /*! Chris@16: * The method flushes the associated streams Chris@16: */ Chris@16: BOOST_LOG_API void flush(); Chris@16: }; Chris@16: Chris@16: #ifdef BOOST_LOG_USE_CHAR Chris@16: typedef basic_text_ostream_backend< char > text_ostream_backend; //!< Convenience typedef for narrow-character logging Chris@16: #endif Chris@16: #ifdef BOOST_LOG_USE_WCHAR_T Chris@16: typedef basic_text_ostream_backend< wchar_t > wtext_ostream_backend; //!< Convenience typedef for wide-character logging Chris@16: #endif Chris@16: Chris@16: } // namespace sinks Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_