$treeview $search $mathjax $extrastylesheet
artdaq_mfextensions
v1_03_03a
$projectbrief
|
$projectbrief
|
$searchbox |
00001 //#define NDEBUG 00002 #define ML_DEBUG // always enable debug 00003 00004 #include <stdlib.h> 00005 #include <cstdio> 00006 #include <fstream> 00007 #include <iostream> 00008 #include <sstream> 00009 #include "fhiclcpp/ParameterSet.h" 00010 #include "fhiclcpp/make_ParameterSet.h" 00011 00012 #include "messagefacility/MessageLogger/MessageLogger.h" 00013 00014 void anotherLogger() { 00015 // Set module name 00016 mf::SetApplicationName("anotherLogger"); 00017 00018 mf::LogWarning("warn1 | warn2") << "Followed by a WARNING message."; 00019 mf::LogDebug("debug") << "The debug message in the other thread"; 00020 00021 return; 00022 } 00023 00024 int main() { 00025 try { 00026 // Start MessageFacility Service 00027 std::ostringstream ss; 00028 std::ifstream logfhicl("MessageFacility.cfg"); 00029 if (logfhicl.is_open()) { 00030 std::stringstream fhiclstream; 00031 fhiclstream << logfhicl.rdbuf(); 00032 ss << fhiclstream.str(); 00033 } 00034 fhicl::ParameterSet pset; 00035 std::string pstr(ss.str()); 00036 fhicl::make_ParameterSet(pstr, pset); 00037 mf::StartMessageFacility(pset); 00038 } catch (std::exception& e) { 00039 std::cerr << "Catched\n" << e.what(); 00040 exit(-1); 00041 } 00042 00043 // Set module name for the main thread 00044 mf::SetApplicationName("mftest"); 00045 00046 // Start up another logger in a seperate thread 00047 // boost::thread loggerThread(anotherLogger); 00048 00049 // Issue messages with different severity levels 00050 // mf::LogError("err1|err2") << "This is an ERROR message."; 00051 // mf::LogWarning("warning") << "Followed by a WARNING message."; 00052 00053 // Switch context 00054 00055 // mf::SwitchChannel(2); 00056 00057 char buf[100]; 00058 00059 // Log Debugs 00060 for (int i = 0; i < 2; ++i) { 00061 if (i % 1000 == 0) { 00062 sprintf(buf, "mftest-%d", i); 00063 mf::SetApplicationName(buf); 00064 } 00065 00066 mf::LogError("catError") << "Error information. " << i; 00067 mf::LogWarning("catWarning") << "Warning information. " << i; 00068 mf::LogInfo("catInfo") << "Info information. " << i; 00069 LOG_DEBUG("debug") << "DEBUG information. " << i; 00070 00071 // sleep(1); 00072 usleep(400000); 00073 } 00074 00075 // Thread join 00076 // loggerThread.join(); 00077 00078 mf::LogStatistics(); 00079 00080 // sleep(2); 00081 00082 return 0; 00083 }