debug_output_backend.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 debug_output_backend.hpp
  9. * \author Andrey Semashev
  10. * \date 07.11.2008
  11. *
  12. * The header contains a logging sink backend that outputs log records to the debugger.
  13. */
  14. #ifndef BOOST_LOG_SINKS_DEBUG_OUTPUT_BACKEND_HPP_INCLUDED_
  15. #define BOOST_LOG_SINKS_DEBUG_OUTPUT_BACKEND_HPP_INCLUDED_
  16. #include <string>
  17. #include <boost/log/detail/config.hpp>
  18. #ifdef BOOST_HAS_PRAGMA_ONCE
  19. #pragma once
  20. #endif
  21. #ifndef BOOST_LOG_WITHOUT_DEBUG_OUTPUT
  22. #include <boost/log/sinks/basic_sink_backend.hpp>
  23. #include <boost/log/sinks/frontend_requirements.hpp>
  24. #include <boost/log/attributes/attribute_value_set.hpp>
  25. #include <boost/log/core/record_view.hpp>
  26. #include <boost/log/detail/header.hpp>
  27. namespace boost {
  28. BOOST_LOG_OPEN_NAMESPACE
  29. namespace sinks {
  30. /*!
  31. * \brief An implementation of a logging sink backend that outputs to the debugger
  32. *
  33. * The sink uses Windows API in order to write log records as debug messages, if the
  34. * application process is run under debugger. The sink backend also provides a specific
  35. * filter that allows to check whether the debugger is available and thus elide unnecessary
  36. * formatting.
  37. */
  38. template< typename CharT >
  39. class basic_debug_output_backend :
  40. public basic_formatted_sink_backend< CharT, concurrent_feeding >
  41. {
  42. //! Base type
  43. typedef basic_formatted_sink_backend< CharT, concurrent_feeding > base_type;
  44. public:
  45. //! Character type
  46. typedef typename base_type::char_type char_type;
  47. //! String type to be used as a message text holder
  48. typedef typename base_type::string_type string_type;
  49. public:
  50. /*!
  51. * Constructor. Initializes the sink backend.
  52. */
  53. BOOST_LOG_API basic_debug_output_backend();
  54. /*!
  55. * Destructor
  56. */
  57. BOOST_LOG_API ~basic_debug_output_backend();
  58. /*!
  59. * The method passes the formatted message to debugger
  60. */
  61. BOOST_LOG_API void consume(record_view const& rec, string_type const& formatted_message);
  62. };
  63. #ifdef BOOST_LOG_USE_CHAR
  64. typedef basic_debug_output_backend< char > debug_output_backend; //!< Convenience typedef for narrow-character logging
  65. #endif
  66. #ifdef BOOST_LOG_USE_WCHAR_T
  67. typedef basic_debug_output_backend< wchar_t > wdebug_output_backend; //!< Convenience typedef for wide-character logging
  68. #endif
  69. } // namespace sinks
  70. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  71. } // namespace boost
  72. #include <boost/log/detail/footer.hpp>
  73. #endif // BOOST_LOG_WITHOUT_DEBUG_OUTPUT
  74. #endif // BOOST_LOG_SINKS_DEBUG_OUTPUT_BACKEND_HPP_INCLUDED_