drop_on_overflow.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 drop_on_overflow.hpp
  9. * \author Andrey Semashev
  10. * \date 04.01.2012
  11. *
  12. * The header contains implementation of \c drop_on_overflow strategy for handling
  13. * queue overflows in bounded queues for the asynchronous sink frontend.
  14. */
  15. #ifndef BOOST_LOG_SINKS_DROP_ON_OVERFLOW_HPP_INCLUDED_
  16. #define BOOST_LOG_SINKS_DROP_ON_OVERFLOW_HPP_INCLUDED_
  17. #include <boost/log/detail/config.hpp>
  18. #include <boost/log/core/record_view.hpp>
  19. #include <boost/log/detail/header.hpp>
  20. #ifdef BOOST_HAS_PRAGMA_ONCE
  21. #pragma once
  22. #endif
  23. namespace boost {
  24. BOOST_LOG_OPEN_NAMESPACE
  25. namespace sinks {
  26. /*!
  27. * \brief Log record dropping strategy
  28. *
  29. * This strategy will cause log records to be discarded in case of
  30. * queue overflow in bounded asynchronous sinks. It should not be used
  31. * if losing log records is not acceptable.
  32. */
  33. class drop_on_overflow
  34. {
  35. #ifndef BOOST_LOG_DOXYGEN_PASS
  36. public:
  37. /*!
  38. * This method is called by the queue when overflow is detected.
  39. *
  40. * \retval true Attempt to enqueue the record again.
  41. * \retval false Discard the record.
  42. */
  43. template< typename LockT >
  44. static bool on_overflow(record_view const&, LockT&)
  45. {
  46. return false;
  47. }
  48. /*!
  49. * This method is called by the queue when there appears a free space.
  50. */
  51. static void on_queue_space_available()
  52. {
  53. }
  54. /*!
  55. * This method is called by the queue to interrupt any possible waits in \c on_overflow.
  56. */
  57. static void interrupt()
  58. {
  59. }
  60. #endif // BOOST_LOG_DOXYGEN_PASS
  61. };
  62. } // namespace sinks
  63. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  64. } // namespace boost
  65. #include <boost/log/detail/footer.hpp>
  66. #endif // BOOST_LOG_SINKS_DROP_ON_OVERFLOW_HPP_INCLUDED_