common_attributes.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 common_attributes.hpp
  9. * \author Andrey Semashev
  10. * \date 16.05.2008
  11. *
  12. * The header contains implementation of convenience functions for registering commonly used attributes.
  13. */
  14. #ifndef BOOST_LOG_UTILITY_SETUP_COMMON_ATTRIBUTES_HPP_INCLUDED_
  15. #define BOOST_LOG_UTILITY_SETUP_COMMON_ATTRIBUTES_HPP_INCLUDED_
  16. #include <iostream>
  17. #include <boost/log/detail/config.hpp>
  18. #include <boost/log/core/core.hpp>
  19. #include <boost/log/attributes/clock.hpp>
  20. #include <boost/log/attributes/counter.hpp>
  21. #include <boost/log/attributes/current_process_id.hpp>
  22. #if !defined(BOOST_LOG_NO_THREADS)
  23. #include <boost/log/attributes/current_thread_id.hpp>
  24. #endif
  25. #include <boost/log/detail/default_attribute_names.hpp>
  26. #include <boost/log/detail/header.hpp>
  27. #ifdef BOOST_HAS_PRAGMA_ONCE
  28. #pragma once
  29. #endif
  30. namespace boost {
  31. BOOST_LOG_OPEN_NAMESPACE
  32. /*!
  33. * \brief Simple attribute initialization routine
  34. *
  35. * The function adds commonly used attributes to the logging system. Specifically, the following
  36. * attributes are registered globally:
  37. *
  38. * \li LineID - logging records counter with value type <tt>unsigned int</tt>
  39. * \li TimeStamp - local time generator with value type <tt>boost::posix_time::ptime</tt>
  40. * \li ProcessID - current process identifier with value type
  41. * <tt>attributes::current_process_id::value_type</tt>
  42. * \li ThreadID - in multithreaded builds, current thread identifier with
  43. * value type <tt>attributes::current_thread_id::value_type</tt>
  44. */
  45. inline void add_common_attributes()
  46. {
  47. shared_ptr< core > pCore = core::get();
  48. pCore->add_global_attribute(
  49. aux::default_attribute_names::line_id(),
  50. attributes::counter< unsigned int >(1));
  51. pCore->add_global_attribute(
  52. aux::default_attribute_names::timestamp(),
  53. attributes::local_clock());
  54. pCore->add_global_attribute(
  55. aux::default_attribute_names::process_id(),
  56. attributes::current_process_id());
  57. #if !defined(BOOST_LOG_NO_THREADS)
  58. pCore->add_global_attribute(
  59. aux::default_attribute_names::thread_id(),
  60. attributes::current_thread_id());
  61. #endif
  62. }
  63. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  64. } // namespace boost
  65. #include <boost/log/detail/footer.hpp>
  66. #endif // BOOST_LOG_UTILITY_SETUP_COMMON_ATTRIBUTES_HPP_INCLUDED_