]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/example/doc/expressions_attr_fmt_tag.cpp
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)
10 #include <boost/log/expressions.hpp>
11 #include <boost/log/sources/severity_logger.hpp>
12 #include <boost/log/sources/record_ostream.hpp>
13 #include <boost/log/utility/formatting_ostream.hpp>
14 #include <boost/log/utility/manipulators/to_log.hpp>
15 #include <boost/log/utility/setup/console.hpp>
16 #include <boost/log/utility/setup/common_attributes.hpp>
18 namespace logging
= boost::log
;
19 namespace src
= boost::log::sources
;
20 namespace expr
= boost::log::expressions
;
21 namespace keywords
= boost::log::keywords
;
23 //[ example_expressions_attr_formatter_stream_tag
24 // We define our own severity levels
34 // The operator is used for regular stream formatting
35 std::ostream
& operator<< (std::ostream
& strm
, severity_level level
)
37 static const char* strings
[] =
46 if (static_cast< std::size_t >(level
) < sizeof(strings
) / sizeof(*strings
))
47 strm
<< strings
[level
];
49 strm
<< static_cast< int >(level
);
54 // Attribute value tag type
57 // The operator is used when putting the severity level to log
58 logging::formatting_ostream
& operator<<
60 logging::formatting_ostream
& strm
,
61 logging::to_log_manip
< severity_level
, severity_tag
> const& manip
64 static const char* strings
[] =
73 severity_level level
= manip
.get();
74 if (static_cast< std::size_t >(level
) < sizeof(strings
) / sizeof(*strings
))
75 strm
<< strings
[level
];
77 strm
<< static_cast< int >(level
);
84 logging::add_console_log
87 // This makes the sink to write log records that look like this:
88 // 1: <NORM> A normal severity message
89 // 2: <ERRR> An error severity message
93 << expr::attr
< unsigned int >("LineID")
94 << ": <" << expr::attr
< severity_level
, severity_tag
>("Severity")
95 << "> " << expr::smessage
101 int main(int, char*[])
104 logging::add_common_attributes();
106 src::severity_logger
< severity_level
> lg
;
108 // These messages will be written with CAPS severity levels
109 BOOST_LOG_SEV(lg
, normal
) << "A normal severity message";
110 BOOST_LOG_SEV(lg
, notification
) << "A notification severity message";
111 BOOST_LOG_SEV(lg
, warning
) << "A warning severity message";
112 BOOST_LOG_SEV(lg
, error
) << "An error severity message";
113 BOOST_LOG_SEV(lg
, critical
) << "A critical severity message";
115 // This line will still use lower-case severity levels
116 std::cout
<< "The regular output still uses lower-case formatting: " << normal
<< std::endl
;