yuu
11/19/2017 - 4:40 AM

[learn] c++ boost

[learn] c++ boost

/*
 * Chapter 62 Boost.Log
 */
// #qo CXXFLAGS: -I/usr/local/include -DBOOST_LOG_DYN_LINK=1
// #qo LIBS: boost_log-mt boost_log_setup-mt
// #qo LIBS: boost_system-mt boost_thread-mt

#include <boost/log/common.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/sources/logger.hpp>
// #include <boost/utility/empty_deleter.hpp> deprecated
#include <boost/core/null_deleter.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>

int main()
{
    using namespace boost::log;
    using text_sink = sinks::asynchronous_sink<sinks::text_ostream_backend>;

    auto sink = boost::make_shared<text_sink>();

    boost::shared_ptr<std::ostream> stream{&std::clog, boost::null_deleter{}};
    sink->locked_backend()->add_stream(stream);

    core::get()->add_sink(sink);

    sources::logger lg;

    BOOST_LOG(lg) << "note";
    sink->flush();

    return 0;
}