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)
9 * \author Andrey Semashev
12 * The header contains an interface declaration for all sinks. This interface is used by the
13 * logging core to feed log records to sinks.
16 #ifndef BOOST_LOG_SINKS_SINK_HPP_INCLUDED_
17 #define BOOST_LOG_SINKS_SINK_HPP_INCLUDED_
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/detail/light_function.hpp>
22 #include <boost/log/core/record_view.hpp>
23 #include <boost/log/attributes/attribute_value_set.hpp>
24 #include <boost/log/detail/header.hpp>
26 #ifdef BOOST_HAS_PRAGMA_ONCE
32 BOOST_LOG_OPEN_NAMESPACE
36 //! A base class for a logging sink frontend
37 class BOOST_LOG_NO_VTABLE sink
40 //! An exception handler type
41 typedef boost::log::aux::light_function< void () > exception_handler_type;
44 //! The flag indicates that the sink passes log records across thread boundaries
45 const bool m_cross_thread;
51 explicit sink(bool cross_thread) : m_cross_thread(cross_thread)
61 * The method returns \c true if no filter is set or the attribute values pass the filter
63 * \param attributes A set of attribute values of a logging record
65 virtual bool will_consume(attribute_value_set const& attributes) = 0;
68 * The method puts logging record to the sink
70 * \param rec Logging record to consume
72 virtual void consume(record_view const& rec) = 0;
75 * The method attempts to put logging record to the sink. The method may be used by the
76 * core in order to determine the most efficient order of sinks to feed records to in
77 * case of heavy contention. Sink implementations may implement try/backoff logic in
78 * order to improve overall logging throughput.
80 * \param rec Logging record to consume
81 * \return \c true, if the record was consumed, \c false, if not.
83 virtual bool try_consume(record_view const& rec)
90 * The method performs flushing of any internal buffers that may hold log records. The method
91 * may take considerable time to complete and may block both the calling thread and threads
92 * attempting to put new records into the sink while this call is in progress.
94 virtual void flush() = 0;
97 * The method indicates that the sink passes log records between different threads. This information is
98 * needed by the logging core to detach log records from all thread-specific resources before passing it
101 bool is_cross_thread() const BOOST_NOEXCEPT { return m_cross_thread; }
103 BOOST_DELETED_FUNCTION(sink(sink const&))
104 BOOST_DELETED_FUNCTION(sink& operator= (sink const&))
109 BOOST_LOG_CLOSE_NAMESPACE // namespace log
113 #include <boost/log/detail/footer.hpp>
115 #endif // BOOST_LOG_SINKS_SINK_HPP_INCLUDED_