Advertisement
mahldcat

BoostLogCode

Aug 5th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. BoostLogger::BoostLogger()
  2. {
  3.     boost::shared_ptr< logging::core > core = logging::core::get();
  4.  
  5.     core->set_exception_handler(
  6.         logging::make_exception_handler<std::runtime_error, std::exception>(BoostExceptionHandler{}));
  7.     boost::shared_ptr< backendSink> backend = NULL;
  8.  
  9.     try {
  10.         backend =
  11.             boost::make_shared< backendSink >((
  12.  
  13. #ifdef _M_IX86
  14.                 keywords::message_file = "c:\\automation\\IISModules\\ModuleCode86.dll",
  15. #else
  16.                 keywords::message_file = "c:\\automation\\IISModules\\ModuleCode64.dll",
  17. #endif
  18.                 keywords::log_name = "Application",
  19.                 keywords::log_source = "IIS Module Source"
  20.                 ));
  21.     }
  22.     catch (std::exception& e) {
  23.         //swallow the error
  24.     }
  25.  
  26.     sinks::event_log::event_composer composer(
  27.         sinks::event_log::direct_event_id_mapping< int >("EventID"));
  28.  
  29.     composer[EVENTLOG_MSG]
  30.         % expr::attr< std::string >("ProcessID")
  31.         % expr::attr< std::string >("ThreadID")
  32.         % expr::attr<std::string>("Message");
  33.     backend->set_event_composer(composer);
  34.  
  35.     sinks::event_log::custom_event_type_mapping< severity_level > type_mapping("Severity");
  36.     type_mapping[debug] = sinks::event_log::make_event_type(LOG_SEVERITY_DEBUG);
  37.     type_mapping[info] = sinks::event_log::make_event_type(LOG_SEVERITY_INFO);
  38.     type_mapping[warning] = sinks::event_log::make_event_type(LOG_SEVERITY_WARNING);
  39.     type_mapping[error] = sinks::event_log::make_event_type(LOG_SEVERITY_WARNING);
  40.     backend->set_event_type_mapper(type_mapping);
  41.  
  42.     sinks::event_log::custom_event_category_mapping< int > cat_mapping("EventID");
  43.     cat_mapping[EVENTLOG_MSG] = sinks::event_log::make_event_category(WINMODULE_LOGGER);
  44.     backend->set_event_category_mapper(cat_mapping);
  45.  
  46.     boost::shared_ptr<sinkImpl> sink(new sinkImpl(backend));
  47.     sink->set_filter(expr::has_attr< int >("EventID"));
  48.     core->add_sink(sink);
  49.     logging::add_common_attributes();
  50.  
  51.     this->logger= loggerImpl();
  52. }
  53.  
  54. void BoostLogger::LogMessage(string message)
  55. {
  56.     string processId = "DEADBEEF";
  57.     string threadId = "FEEDC0DE";
  58.     //int
  59.     BOOST_LOG_SCOPED_THREAD_TAG("EventID", (int)EVENTLOG_MSG);
  60.     BOOST_LOG_SCOPED_THREAD_TAG("ProcessID", processId);
  61.     BOOST_LOG_SCOPED_THREAD_TAG("ThreadID", threadId);
  62.     BOOST_LOG_SCOPED_THREAD_TAG("Message", message);
  63.  
  64.     BOOST_LOG_SEV(this->logger, info)<< message ;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement