Last active
March 26, 2016 14:26
-
-
Save dorgonman/fdab8f1be4a11a4a4fbc to your computer and use it in GitHub Desktop.
HorizonCore::initDefaultLog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace logging = boost::log; | |
namespace attrs = boost::log::attributes; | |
namespace src = boost::log::sources; | |
namespace sinks = boost::log::sinks; | |
namespace expr = boost::log::expressions; | |
namespace keywords = boost::log::keywords; | |
void HorizonCore::initDefaultLog(const std::string& fileLogFullPath, | |
horizon::HorizonLogImpFunc_t&& logFunc, | |
boost::log::trivial::severity_level logFilterLevel, | |
boost::log::trivial::severity_level fileLogFilterLevel){ | |
logging::core::get()->remove_all_sinks(); | |
//typedef boost::log::sinks::synchronous_sink<HorizonLogBasicBackend> HorizonLogSink; | |
typedef boost::log::sinks::synchronous_sink<HorizonLogBasicFormatedBackend> HorizonLogSink; | |
auto sink = boost::make_shared<HorizonLogSink>(); | |
sink->locked_backend()->setLogMessageImplemen(std::forward<horizon::HorizonLogImpFunc_t>(logFunc)); | |
boost::log::core::get()->add_sink(sink); | |
boost::log::add_common_attributes(); | |
auto logFormat = expr::format("%1%: [%2%] [%3%]: %4%") | |
% expr::attr< unsigned int >("RecordID") | |
% expr::attr< boost::log::trivial::severity_level >("Severity") | |
% expr::attr< boost::posix_time::ptime >("TimeStamp") | |
% expr::smessage; | |
//% expr::attr< unsigned int >("Function"); | |
sink->set_formatter(logFormat); | |
sink->set_filter(logging::trivial::severity >= logFilterLevel); | |
logging::core::get()->add_global_attribute("RecordID", attrs::counter< unsigned int >()); | |
logging::core::get()->add_global_attribute("TimeStamp", attrs::local_clock()); | |
logging::add_file_log( | |
keywords::file_name = fileLogFullPath | |
, keywords::auto_flush = true | |
, keywords::filter = expr::attr< boost::log::trivial::severity_level >("Severity") >= fileLogFilterLevel | |
, keywords::format = (logFormat) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment