Skip to content

Instantly share code, notes, and snippets.

@yuu
Last active March 6, 2020 01:39
Show Gist options
  • Save yuu/3bd0accba8b01245da48c17b337ecc84 to your computer and use it in GitHub Desktop.
Save yuu/3bd0accba8b01245da48c17b337ecc84 to your computer and use it in GitHub Desktop.
[c++] [boost] learn boost tutorial
/*
* 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment