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 sink.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 22.04.2007 Chris@16: * Chris@16: * The header contains an interface declaration for all sinks. This interface is used by the Chris@16: * logging core to feed log records to sinks. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_SINKS_SINK_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_SINKS_SINK_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: //! A base class for a logging sink frontend Chris@16: class BOOST_LOG_NO_VTABLE sink Chris@16: { Chris@16: public: Chris@16: //! An exception handler type Chris@16: typedef boost::log::aux::light_function< void () > exception_handler_type; Chris@16: Chris@16: private: Chris@16: //! The flag indicates that the sink passes log records across thread boundaries Chris@16: const bool m_cross_thread; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Default constructor Chris@16: */ Chris@16: explicit sink(bool cross_thread) : m_cross_thread(cross_thread) Chris@16: { Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Virtual destructor Chris@16: */ Chris@16: virtual ~sink() {} Chris@16: Chris@16: /*! Chris@16: * The method returns \c true if no filter is set or the attribute values pass the filter Chris@16: * Chris@16: * \param attributes A set of attribute values of a logging record Chris@16: */ Chris@16: virtual bool will_consume(attribute_value_set const& attributes) = 0; Chris@16: Chris@16: /*! Chris@16: * The method puts logging record to the sink Chris@16: * Chris@16: * \param rec Logging record to consume Chris@16: */ Chris@16: virtual void consume(record_view const& rec) = 0; Chris@16: Chris@16: /*! Chris@16: * The method attempts to put logging record to the sink. The method may be used by the Chris@16: * core in order to determine the most efficient order of sinks to feed records to in Chris@16: * case of heavy contention. Sink implementations may implement try/backoff logic in Chris@16: * order to improve overall logging throughput. Chris@16: * Chris@16: * \param rec Logging record to consume Chris@16: * \return \c true, if the record was consumed, \c false, if not. Chris@16: */ Chris@16: virtual bool try_consume(record_view const& rec) Chris@16: { Chris@16: consume(rec); Chris@16: return true; Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The method performs flushing of any internal buffers that may hold log records. The method Chris@16: * may take considerable time to complete and may block both the calling thread and threads Chris@16: * attempting to put new records into the sink while this call is in progress. Chris@16: */ Chris@16: virtual void flush() = 0; Chris@16: Chris@16: /*! Chris@16: * The method indicates that the sink passes log records between different threads. This information is Chris@16: * needed by the logging core to detach log records from all thread-specific resources before passing it Chris@16: * to the sink. Chris@16: */ Chris@16: bool is_cross_thread() const BOOST_NOEXCEPT { return m_cross_thread; } Chris@16: Chris@16: BOOST_DELETED_FUNCTION(sink(sink const&)) Chris@16: BOOST_DELETED_FUNCTION(sink& operator= (sink const&)) Chris@16: }; 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_SINK_HPP_INCLUDED_