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 sink.hpp
|
Chris@16
|
9 * \author Andrey Semashev
|
Chris@16
|
10 * \date 22.04.2007
|
Chris@16
|
11 *
|
Chris@16
|
12 * The header contains an interface declaration for all sinks. This interface is used by the
|
Chris@16
|
13 * logging core to feed log records to sinks.
|
Chris@16
|
14 */
|
Chris@16
|
15
|
Chris@16
|
16 #ifndef BOOST_LOG_SINKS_SINK_HPP_INCLUDED_
|
Chris@16
|
17 #define BOOST_LOG_SINKS_SINK_HPP_INCLUDED_
|
Chris@16
|
18
|
Chris@16
|
19 #include <string>
|
Chris@16
|
20 #include <boost/log/detail/config.hpp>
|
Chris@16
|
21 #include <boost/log/detail/light_function.hpp>
|
Chris@16
|
22 #include <boost/log/core/record_view.hpp>
|
Chris@16
|
23 #include <boost/log/attributes/attribute_value_set.hpp>
|
Chris@16
|
24 #include <boost/log/detail/header.hpp>
|
Chris@16
|
25
|
Chris@16
|
26 #ifdef BOOST_HAS_PRAGMA_ONCE
|
Chris@16
|
27 #pragma once
|
Chris@16
|
28 #endif
|
Chris@16
|
29
|
Chris@16
|
30 namespace boost {
|
Chris@16
|
31
|
Chris@16
|
32 BOOST_LOG_OPEN_NAMESPACE
|
Chris@16
|
33
|
Chris@16
|
34 namespace sinks {
|
Chris@16
|
35
|
Chris@16
|
36 //! A base class for a logging sink frontend
|
Chris@16
|
37 class BOOST_LOG_NO_VTABLE sink
|
Chris@16
|
38 {
|
Chris@16
|
39 public:
|
Chris@16
|
40 //! An exception handler type
|
Chris@16
|
41 typedef boost::log::aux::light_function< void () > exception_handler_type;
|
Chris@16
|
42
|
Chris@16
|
43 private:
|
Chris@16
|
44 //! The flag indicates that the sink passes log records across thread boundaries
|
Chris@16
|
45 const bool m_cross_thread;
|
Chris@16
|
46
|
Chris@16
|
47 public:
|
Chris@16
|
48 /*!
|
Chris@16
|
49 * Default constructor
|
Chris@16
|
50 */
|
Chris@16
|
51 explicit sink(bool cross_thread) : m_cross_thread(cross_thread)
|
Chris@16
|
52 {
|
Chris@16
|
53 }
|
Chris@16
|
54
|
Chris@16
|
55 /*!
|
Chris@16
|
56 * Virtual destructor
|
Chris@16
|
57 */
|
Chris@16
|
58 virtual ~sink() {}
|
Chris@16
|
59
|
Chris@16
|
60 /*!
|
Chris@16
|
61 * The method returns \c true if no filter is set or the attribute values pass the filter
|
Chris@16
|
62 *
|
Chris@16
|
63 * \param attributes A set of attribute values of a logging record
|
Chris@16
|
64 */
|
Chris@16
|
65 virtual bool will_consume(attribute_value_set const& attributes) = 0;
|
Chris@16
|
66
|
Chris@16
|
67 /*!
|
Chris@16
|
68 * The method puts logging record to the sink
|
Chris@16
|
69 *
|
Chris@16
|
70 * \param rec Logging record to consume
|
Chris@16
|
71 */
|
Chris@16
|
72 virtual void consume(record_view const& rec) = 0;
|
Chris@16
|
73
|
Chris@16
|
74 /*!
|
Chris@16
|
75 * The method attempts to put logging record to the sink. The method may be used by the
|
Chris@16
|
76 * core in order to determine the most efficient order of sinks to feed records to in
|
Chris@16
|
77 * case of heavy contention. Sink implementations may implement try/backoff logic in
|
Chris@16
|
78 * order to improve overall logging throughput.
|
Chris@16
|
79 *
|
Chris@16
|
80 * \param rec Logging record to consume
|
Chris@16
|
81 * \return \c true, if the record was consumed, \c false, if not.
|
Chris@16
|
82 */
|
Chris@16
|
83 virtual bool try_consume(record_view const& rec)
|
Chris@16
|
84 {
|
Chris@16
|
85 consume(rec);
|
Chris@16
|
86 return true;
|
Chris@16
|
87 }
|
Chris@16
|
88
|
Chris@16
|
89 /*!
|
Chris@16
|
90 * The method performs flushing of any internal buffers that may hold log records. The method
|
Chris@16
|
91 * may take considerable time to complete and may block both the calling thread and threads
|
Chris@16
|
92 * attempting to put new records into the sink while this call is in progress.
|
Chris@16
|
93 */
|
Chris@16
|
94 virtual void flush() = 0;
|
Chris@16
|
95
|
Chris@16
|
96 /*!
|
Chris@16
|
97 * The method indicates that the sink passes log records between different threads. This information is
|
Chris@16
|
98 * needed by the logging core to detach log records from all thread-specific resources before passing it
|
Chris@16
|
99 * to the sink.
|
Chris@16
|
100 */
|
Chris@16
|
101 bool is_cross_thread() const BOOST_NOEXCEPT { return m_cross_thread; }
|
Chris@16
|
102
|
Chris@16
|
103 BOOST_DELETED_FUNCTION(sink(sink const&))
|
Chris@16
|
104 BOOST_DELETED_FUNCTION(sink& operator= (sink const&))
|
Chris@16
|
105 };
|
Chris@16
|
106
|
Chris@16
|
107 } // namespace sinks
|
Chris@16
|
108
|
Chris@16
|
109 BOOST_LOG_CLOSE_NAMESPACE // namespace log
|
Chris@16
|
110
|
Chris@16
|
111 } // namespace boost
|
Chris@16
|
112
|
Chris@16
|
113 #include <boost/log/detail/footer.hpp>
|
Chris@16
|
114
|
Chris@16
|
115 #endif // BOOST_LOG_SINKS_SINK_HPP_INCLUDED_
|