标签:
#include <boost/log/utility/setup/common_attributes.hpp>
int main()
{
boost::log::add_common_attributes();
return 0;
}
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/severity_feature.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
enum severity_level
{
normal,
notification,
warning,
error,
critical
};
void logging_function()
{
boost::log::sources::severity_logger< severity_level > slg;
BOOST_LOG_SEV(slg, normal) << "A regular message";
BOOST_LOG_SEV(slg, warning) << "Something bad is going on but I can handle it";
BOOST_LOG_SEV(slg, critical) << "Everything crumbles, shoot me now!";
}
#include <boost/log/keywords/severity.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/severity_feature.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
enum severity_level
{
normal,
notification,
warning,
error,
critical
};
void manual_logging()
{
boost::log::sources::severity_logger< severity_level > slg;
boost::log::record rec = slg.open_record(boost::log::keywords::severity = normal);
if (rec)
{
boost::log::record_ostream strm(rec);
strm << "A regular message";
strm.flush();
slg.push_record(boost::move(rec));
}
}
inline void add_common_attributes()
{
shared_ptr< core > pCore = core::get();
pCore->add_global_attribute(
aux::default_attribute_names::line_id(),
attributes::counter< unsigned int >(1));
pCore->add_global_attribute(
aux::default_attribute_names::timestamp(),
attributes::local_clock());
pCore->add_global_attribute(
aux::default_attribute_names::process_id(),
attributes::current_process_id());
#if !defined(BOOST_LOG_NO_THREADS)
pCore->add_global_attribute(
aux::default_attribute_names::thread_id(),
attributes::current_thread_id());
#endif
}
boost::log::core::get()->add_global_attribute("Scope", boost::log::attributes::named_scope());
void named_scope_logging()
{
BOOST_LOG_NAMED_SCOPE("named_scope_logging");
boost::log::sources::severity_logger< severity_level > slg;
BOOST_LOG_SEV(slg, normal) << "Hello from the function named_scope_logging!";
}
void tagged_logging()
{
boost::log::sources::severity_logger< severity_level > slg;
slg.add_attribute("Tag", boost::log::attributes::constant< std::string >("My tag value"));
BOOST_LOG_SEV(slg, normal) << "Here goes the tagged record";
}
void timed_logging()
{
BOOST_LOG_SCOPED_THREAD_ATTR("Timeline", boost::log::attributes::timer());
boost::log::sources::severity_logger< severity_level > slg;
BOOST_LOG_SEV(slg, normal) << "Starting to time nested functions";
logging_function();
BOOST_LOG_SEV(slg, normal) << "Stopping to time nested functions";
}
BOOST_LOG_ATTRIBUTE_KEYWORD(line_id, "LineID", unsigned int)
BOOST_LOG_ATTRIBUTE_KEYWORD(severity, "Severity", severity_level)
BOOST_LOG_ATTRIBUTE_KEYWORD(tag_attr, "Tag", std::string)
BOOST_LOG_ATTRIBUTE_KEYWORD(scope, "Scope", boost::log::attributes::named_scope::value_type)
BOOST_LOG_ATTRIBUTE_KEYWORD(timeline, "Timeline", boost::log::attributes::timer::value_type)
标签:
原文地址:http://www.cnblogs.com/zhangpanyi/p/4484289.html