current_process_name.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 current_process_name.hpp
  9. * \author Andrey Semashev
  10. * \date 29.07.2012
  11. *
  12. * The header contains implementation of a current process name attribute
  13. */
  14. #ifndef BOOST_LOG_ATTRIBUTES_CURRENT_PROCESS_NAME_HPP_INCLUDED_
  15. #define BOOST_LOG_ATTRIBUTES_CURRENT_PROCESS_NAME_HPP_INCLUDED_
  16. #include <string>
  17. #include <boost/log/detail/config.hpp>
  18. #include <boost/log/attributes/constant.hpp>
  19. #include <boost/log/attributes/attribute_cast.hpp>
  20. #include <boost/log/detail/header.hpp>
  21. #ifdef BOOST_HAS_PRAGMA_ONCE
  22. #pragma once
  23. #endif
  24. namespace boost {
  25. BOOST_LOG_OPEN_NAMESPACE
  26. namespace aux {
  27. //! The function returns the current process name
  28. BOOST_LOG_API std::string get_process_name();
  29. } // namespace aux
  30. namespace attributes {
  31. /*!
  32. * \brief A class of an attribute that holds the current process name
  33. */
  34. class current_process_name :
  35. public constant< std::string >
  36. {
  37. typedef constant< std::string > base_type;
  38. public:
  39. /*!
  40. * Constructor. Initializes the attribute with the current process name.
  41. */
  42. current_process_name() : base_type(boost::log::aux::get_process_name()) {}
  43. /*!
  44. * Constructor for casting support
  45. */
  46. explicit current_process_name(cast_source const& source) :
  47. base_type(source)
  48. {
  49. }
  50. };
  51. } // namespace attributes
  52. BOOST_LOG_CLOSE_NAMESPACE // namespace log
  53. } // namespace boost
  54. #include <boost/log/detail/footer.hpp>
  55. #endif // BOOST_LOG_ATTRIBUTES_CURRENT_PROCESS_NAME_HPP_INCLUDED_