Chris@16
|
1 /*
|
Chris@101
|
2 * Copyright Andrey Semashev 2007 - 2015.
|
Chris@16
|
3 * Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
4 * (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
5 * http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 */
|
Chris@16
|
7 /*!
|
Chris@16
|
8 * \file text_ostream_backend.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 22.04.2007
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains implementation of a text output stream sink backend.
|
Chris@16
|
13 */
|
Chris@16
|
14
|
Chris@16
|
15 #ifndef BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_
|
Chris@16
|
16 #define BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_
|
Chris@16
|
17
|
Chris@16
|
18 #include <ostream>
|
Chris@16
|
19 #include <boost/smart_ptr/shared_ptr.hpp>
|
Chris@16
|
20 #include <boost/log/detail/config.hpp>
|
Chris@16
|
21 #include <boost/log/sinks/basic_sink_backend.hpp>
|
Chris@16
|
22 #include <boost/log/sinks/frontend_requirements.hpp>
|
Chris@16
|
23 #include <boost/log/detail/header.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
26 #pragma once
|
Chris@16
|
27 #endif
|
Chris@16
|
28
|
Chris@16
|
29 namespace boost {
|
Chris@16
|
30
|
Chris@16
|
31 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
32
|
Chris@16
|
33 namespace sinks {
|
Chris@16
|
34
|
Chris@16
|
35 /*!
|
Chris@16
|
36 * \brief An implementation of a text output stream logging sink backend
|
Chris@16
|
37 *
|
Chris@16
|
38 * The sink backend puts formatted log records to one or more text streams.
|
Chris@16
|
39 */
|
Chris@16
|
40 template< typename CharT >
|
Chris@16
|
41 class basic_text_ostream_backend :
|
Chris@16
|
42 public basic_formatted_sink_backend<
|
Chris@16
|
43 CharT,
|
Chris@16
|
44 combine_requirements< synchronized_feeding, flushing >::type
|
Chris@16
|
45 >
|
Chris@16
|
46 {
|
Chris@16
|
47 //! Base type
|
Chris@16
|
48 typedef basic_formatted_sink_backend<
|
Chris@16
|
49 CharT,
|
Chris@16
|
50 combine_requirements< synchronized_feeding, flushing >::type
|
Chris@16
|
51 > base_type;
|
Chris@16
|
52
|
Chris@16
|
53 public:
|
Chris@16
|
54 //! Character type
|
Chris@16
|
55 typedef typename base_type::char_type char_type;
|
Chris@16
|
56 //! String type to be used as a message text holder
|
Chris@16
|
57 typedef typename base_type::string_type string_type;
|
Chris@16
|
58 //! Output stream type
|
Chris@16
|
59 typedef std::basic_ostream< char_type > stream_type;
|
Chris@16
|
60
|
Chris@16
|
61 private:
|
Chris@16
|
62 //! \cond
|
Chris@16
|
63
|
Chris@16
|
64 struct implementation;
|
Chris@16
|
65 implementation* m_pImpl;
|
Chris@16
|
66
|
Chris@16
|
67 //! \endcond
|
Chris@16
|
68
|
Chris@16
|
69 public:
|
Chris@16
|
70 /*!
|
Chris@16
|
71 * Constructor. No streams attached to the constructed backend, auto flush feature disabled.
|
Chris@16
|
72 */
|
Chris@16
|
73 BOOST_LOG_API basic_text_ostream_backend();
|
Chris@16
|
74 /*!
|
Chris@16
|
75 * Destructor
|
Chris@16
|
76 */
|
Chris@16
|
77 BOOST_LOG_API ~basic_text_ostream_backend();
|
Chris@16
|
78
|
Chris@16
|
79 /*!
|
Chris@16
|
80 * The method adds a new stream to the sink.
|
Chris@16
|
81 *
|
Chris@16
|
82 * \param strm Pointer to the stream. Must not be NULL.
|
Chris@16
|
83 */
|
Chris@16
|
84 BOOST_LOG_API void add_stream(shared_ptr< stream_type > const& strm);
|
Chris@16
|
85 /*!
|
Chris@16
|
86 * The method removes a stream from the sink. If the stream is not attached to the sink,
|
Chris@16
|
87 * the method has no effect.
|
Chris@16
|
88 *
|
Chris@16
|
89 * \param strm Pointer to the stream. Must not be NULL.
|
Chris@16
|
90 */
|
Chris@16
|
91 BOOST_LOG_API void remove_stream(shared_ptr< stream_type > const& strm);
|
Chris@16
|
92
|
Chris@16
|
93 /*!
|
Chris@16
|
94 * Sets the flag to automatically flush buffers of all attached streams after each log record
|
Chris@16
|
95 */
|
Chris@16
|
96 BOOST_LOG_API void auto_flush(bool f = true);
|
Chris@16
|
97
|
Chris@16
|
98 /*!
|
Chris@16
|
99 * The method writes the message to the sink
|
Chris@16
|
100 */
|
Chris@16
|
101 BOOST_LOG_API void consume(record_view const& rec, string_type const& formatted_message);
|
Chris@16
|
102
|
Chris@16
|
103 /*!
|
Chris@16
|
104 * The method flushes the associated streams
|
Chris@16
|
105 */
|
Chris@16
|
106 BOOST_LOG_API void flush();
|
Chris@16
|
107 };
|
Chris@16
|
108
|
Chris@16
|
109 #ifdef BOOST_LOG_USE_CHAR
|
Chris@16
|
110 typedef basic_text_ostream_backend< char > text_ostream_backend; //!< Convenience typedef for narrow-character logging
|
Chris@16
|
111 #endif
|
Chris@16
|
112 #ifdef BOOST_LOG_USE_WCHAR_T
|
Chris@16
|
113 typedef basic_text_ostream_backend< wchar_t > wtext_ostream_backend; //!< Convenience typedef for wide-character logging
|
Chris@16
|
114 #endif
|
Chris@16
|
115
|
Chris@16
|
116 } // namespace sinks
|
Chris@16
|
117
|
Chris@16
|
118 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
119
|
Chris@16
|
120 } // namespace boost
|
Chris@16
|
121
|
Chris@16
|
122 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
123
|
Chris@16
|
124 #endif // BOOST_LOG_SINKS_TEXT_OSTREAM_BACKEND_HPP_INCLUDED_
|