util_manip_to_log.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #include <cstddef>
  8. #include <iomanip>
  9. #include <iostream>
  10. #include <boost/log/utility/formatting_ostream.hpp>
  11. #include <boost/log/utility/manipulators/to_log.hpp>
  12. namespace logging = boost::log;
  13. //[ example_utility_manipulators_to_log
  14. std::ostream& operator<<
  15. (
  16. std::ostream& strm,
  17. logging::to_log_manip< int > const& manip
  18. )
  19. {
  20. strm << std::setw(4) << std::setfill('0') << std::hex << manip.get() << std::dec;
  21. return strm;
  22. }
  23. void test_manip()
  24. {
  25. std::cout << "Regular output: " << 1010 << std::endl;
  26. std::cout << "Log output: " << logging::to_log(1010) << std::endl;
  27. }
  28. //]
  29. //[ example_utility_manipulators_to_log_with_tag
  30. struct tag_A;
  31. struct tag_B;
  32. std::ostream& operator<<
  33. (
  34. std::ostream& strm,
  35. logging::to_log_manip< int, tag_A > const& manip
  36. )
  37. {
  38. strm << "A[" << manip.get() << "]";
  39. return strm;
  40. }
  41. std::ostream& operator<<
  42. (
  43. std::ostream& strm,
  44. logging::to_log_manip< int, tag_B > const& manip
  45. )
  46. {
  47. strm << "B[" << manip.get() << "]";
  48. return strm;
  49. }
  50. void test_manip_with_tag()
  51. {
  52. std::cout << "Regular output: " << 1010 << std::endl;
  53. std::cout << "Log output A: " << logging::to_log< tag_A >(1010) << std::endl;
  54. std::cout << "Log output B: " << logging::to_log< tag_B >(1010) << std::endl;
  55. }
  56. //]
  57. int main(int, char*[])
  58. {
  59. test_manip();
  60. test_manip_with_tag();
  61. return 0;
  62. }