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