]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/log/example/doc/tutorial_fmt_stream_manual.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/smart_ptr/shared_ptr.hpp>
11 #include <boost/smart_ptr/make_shared_object.hpp>
12 #include <boost/log/core.hpp>
13 #include <boost/log/trivial.hpp>
14 #include <boost/log/expressions.hpp>
15 #include <boost/log/sinks/sync_frontend.hpp>
16 #include <boost/log/sinks/text_ostream_backend.hpp>
17 #include <boost/log/sources/severity_logger.hpp>
18 #include <boost/log/sources/record_ostream.hpp>
19 #include <boost/log/utility/setup/common_attributes.hpp>
21 namespace logging
= boost::log
;
22 namespace src
= boost::log::sources
;
23 namespace expr
= boost::log::expressions
;
24 namespace sinks
= boost::log::sinks
;
25 namespace keywords
= boost::log::keywords
;
27 //[ example_tutorial_formatters_stream_manual
30 typedef sinks::synchronous_sink
< sinks::text_ostream_backend
> text_sink
;
31 boost::shared_ptr
< text_sink
> sink
= boost::make_shared
< text_sink
>();
33 sink
->locked_backend()->add_stream(
34 boost::make_shared
< std::ofstream
>("sample.log"));
39 // line id will be written in hex, 8-digits, zero-filled
40 << std::hex
<< std::setw(8) << std::setfill('0') << expr::attr
< unsigned int >("LineID")
41 << ": <" << logging::trivial::severity
42 << "> " << expr::smessage
45 logging::core::get()->add_sink(sink
);
49 int main(int, char*[])
52 logging::add_common_attributes();
54 using namespace logging::trivial
;
55 src::severity_logger
< severity_level
> lg
;
57 BOOST_LOG_SEV(lg
, trace
) << "A trace severity message";
58 BOOST_LOG_SEV(lg
, debug
) << "A debug severity message";
59 BOOST_LOG_SEV(lg
, info
) << "An informational severity message";
60 BOOST_LOG_SEV(lg
, warning
) << "A warning severity message";
61 BOOST_LOG_SEV(lg
, error
) << "An error severity message";
62 BOOST_LOG_SEV(lg
, fatal
) << "A fatal severity message";