• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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)
6  */
7 /*!
8  * \file   sink.hpp
9  * \author Andrey Semashev
10  * \date   22.04.2007
11  *
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.
14  */
15 
16 #ifndef BOOST_LOG_SINKS_SINK_HPP_INCLUDED_
17 #define BOOST_LOG_SINKS_SINK_HPP_INCLUDED_
18 
19 #include <string>
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>
25 
26 #ifdef BOOST_HAS_PRAGMA_ONCE
27 #pragma once
28 #endif
29 
30 namespace boost {
31 
32 BOOST_LOG_OPEN_NAMESPACE
33 
34 namespace sinks {
35 
36 //! A base class for a logging sink frontend
37 class BOOST_LOG_NO_VTABLE sink
38 {
39 public:
40     //! An exception handler type
41     typedef boost::log::aux::light_function< void () > exception_handler_type;
42 
43 private:
44     //! The flag indicates that the sink passes log records across thread boundaries
45     const bool m_cross_thread;
46 
47 public:
48     /*!
49      * Default constructor
50      */
sink(bool cross_thread)51     explicit sink(bool cross_thread) : m_cross_thread(cross_thread)
52     {
53     }
54 
55     /*!
56      * Virtual destructor
57      */
~sink()58     virtual ~sink() {}
59 
60     /*!
61      * The method returns \c true if no filter is set or the attribute values pass the filter
62      *
63      * \param attributes A set of attribute values of a logging record
64      */
65     virtual bool will_consume(attribute_value_set const& attributes) = 0;
66 
67     /*!
68      * The method puts logging record to the sink
69      *
70      * \param rec Logging record to consume
71      */
72     virtual void consume(record_view const& rec) = 0;
73 
74     /*!
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.
79      *
80      * \param rec Logging record to consume
81      * \return \c true, if the record was consumed, \c false, if not.
82      */
try_consume(record_view const & rec)83     virtual bool try_consume(record_view const& rec)
84     {
85         consume(rec);
86         return true;
87     }
88 
89     /*!
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.
93      */
94     virtual void flush() = 0;
95 
96     /*!
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
99      * to the sink.
100      */
is_cross_thread() const101     bool is_cross_thread() const BOOST_NOEXCEPT { return m_cross_thread; }
102 
103     BOOST_DELETED_FUNCTION(sink(sink const&))
104     BOOST_DELETED_FUNCTION(sink& operator= (sink const&))
105 };
106 
107 } // namespace sinks
108 
109 BOOST_LOG_CLOSE_NAMESPACE // namespace log
110 
111 } // namespace boost
112 
113 #include <boost/log/detail/footer.hpp>
114 
115 #endif // BOOST_LOG_SINKS_SINK_HPP_INCLUDED_
116