sink.hpp 3.3 KB

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