标签:
#include <iostream>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
void init()
{
boost::log::add_file_log("sample.log");
boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info);
}
#include <iostream>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
void init()
{
boost::log::add_file_log(
boost::log::keywords::file_name = "sample_%N.log",
boost::log::keywords::rotation_size = 10 * 1024 * 1024,
boost::log::keywords::time_based_rotation = boost::log::sinks::file::rotation_at_time_point(0, 0, 0),
boost::log::keywords::format = "[%TimeStamp%]: %Message%"
);
boost::log::core::get()->set_filter(boost::log::trivial::severity >= boost::log::trivial::info);
}
#include <fstream>
#include <boost/log/core.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
void init()
{
// 构造接收器
typedef boost::log::sinks::synchronous_sink<boost::log::sinks::text_ostream_backend > text_sink;
boost::shared_ptr<text_sink> sink = boost::make_shared<text_sink>();
// 添加一个流写入日志
sink->locked_backend()->add_stream(boost::make_shared< std::ofstream >("sample.log"));
// 注册接收器
boost::log::core::get()->add_sink(sink);
}
#include <boost/log/core.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/log/trivial.hpp>
#include <boost/core/null_deleter.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
void init()
{
// 构造接收器
typedef boost::log::sinks::synchronous_sink<boost::log::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::null_deleter());
sink->locked_backend()->add_stream(stream);
// 注册接收器
boost::log::core::get()->add_sink(sink);
}
标签:
原文地址:http://www.cnblogs.com/zhangpanyi/p/4484281.html