C++ boost::log function














































C++ boost::log function



Description:

Boost.log is the logging library in Boost. It supports numerous back-ends to log data in various formats.
It works under boost::log

Header:

#include<boost/log/function.hpp>

Using boost::log function:

#include <boost/log/common.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/utility/empty_deleter.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>

using namespace boost::log;

bool only_warnings(const attribute_value_set &set)
{
return set["Severity"].extract<int>();
}

int main()
{
typedef sinks::asynchronous_sink<sinks::text_ostream_backend> text_sink;
boost::
shared_ptr<text_sink> sink = boost::make_shared<text_sink>();

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

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

sources::severity_logger<
int> lg;

BOOST_LOG(lg) <<
"note";
BOOST_LOG_SEV(lg,
0) << "another note";
BOOST_LOG_SEV(lg,
1) << "warning";
sink->flush();
}

Output:

Warning.

Comments