$treeview $search $mathjax $extrastylesheet
artdaq_mfextensions
v1_03_03
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "mfextensions/Receivers/LogReader_receiver.hh" 00002 #include <iostream> 00003 #include "mfextensions/Receivers/ReceiverMacros.hh" 00004 00005 mfviewer::LogReader::LogReader(fhicl::ParameterSet pset) 00006 : MVReceiver(pset), 00007 log_(), 00008 pos_(0), 00009 filename_(pset.get<std::string>("filename")), 00010 counter_(0), 00011 metadata_1( 00012 "\\%MSG-([wide])\\s([^:]*):\\s\\s([^\\s]*)\\s*(\\d\\d-[^-]*-\\d{4}\\s\\d+:\\d+:\\d+)\\s.[DS]T\\s\\s(\\w+)") 00013 //, metadata_2 00014 // ( "([^\\s]*)\\s([^\\s]*)\\s([^\\s]*)\\s(([^\\s]*)\\s)?([^:]*):(\\d*)" ) 00015 { 00016 std::cout << "LogReader_receiver Constructor" << std::endl; 00017 } 00018 00019 mfviewer::LogReader::~LogReader() { log_.close(); } 00020 00021 void mfviewer::LogReader::run() { 00022 while (!stopRequested_) { 00023 log_.open(filename_.c_str(), std::fstream::in); 00024 log_.seekg(pos_); 00025 00026 if (log_.is_open() && log_.good()) { 00027 bool msgFound = false; 00028 while (!msgFound) { 00029 if (log_.eof()) { 00030 break; 00031 } 00032 00033 std::string line; 00034 pos_ = log_.tellg(); 00035 getline(log_, line); 00036 if (line.find("%MSG") != std::string::npos) { 00037 msgFound = true; 00038 log_.seekg(pos_); 00039 } 00040 } 00041 00042 if (msgFound) { 00043 std::cout << "Message found, emitting!" << std::endl; 00044 emit NewMessage(read_next()); 00045 ++counter_; 00046 } 00047 log_.clear(); 00048 pos_ = log_.tellg(); 00049 } 00050 00051 log_.clear(); 00052 log_.close(); 00053 usleep(500000); 00054 // sleep(1); 00055 } 00056 00057 std::cout << "LogReader_receiver shutting down!" << std::endl; 00058 } 00059 00060 #include <time.h> 00061 #include <iostream> 00062 00063 qt_mf_msg mfviewer::LogReader::read_next() { 00064 std::string line; 00065 00066 // meta data 1 00067 getline(log_, line); 00068 00069 std::string category, application, eventID; 00070 timeval tv = {0, 0}; 00071 sev_code_t sev = SERROR; 00072 00073 if (boost::regex_search(line, what_, metadata_1)) { 00074 #if 0 00075 std::cout << ">> " << std::string(what_[1].first, what_[1].second) << "\n"; 00076 std::cout << ">> " << std::string(what_[2].first, what_[2].second) << "\n"; 00077 std::cout << ">> " << std::string(what_[3].first, what_[3].second) << "\n"; 00078 std::cout << ">> " << std::string(what_[4].first, what_[4].second) << "\n"; 00079 std::cout << ">> " << std::string(what_[5].first, what_[5].second) << "\n"; 00080 #endif 00081 00082 std::string value = std::string(what_[1].first, what_[1].second); 00083 00084 switch (value[0]) { 00085 case 'e': 00086 sev = SERROR; 00087 break; 00088 case 'w': 00089 sev = SWARNING; 00090 break; 00091 case 'i': 00092 sev = SINFO; 00093 break; 00094 case 'd': 00095 sev = SDEBUG; 00096 break; 00097 default: 00098 break; 00099 } 00100 00101 struct tm tm; 00102 time_t t; 00103 00104 value = std::string(what_[4].first, what_[4].second); 00105 strptime(value.c_str(), "%d-%b-%Y %H:%M:%S", &tm); 00106 00107 tm.tm_isdst = -1; 00108 t = mktime(&tm); 00109 tv.tv_sec = t; 00110 tv.tv_usec = 0; 00111 00112 category = std::string(what_[2].first, what_[2].second); 00113 application = std::string(what_[3].first, what_[3].second); 00114 00115 eventID = std::string(what_[5].first, what_[5].second); 00116 // msg.setHostname ( std::string(what_[4].first, what_[4].second) ); 00117 // msg.setHostaddr ( std::string(what_[5].first, what_[5].second) ); 00118 } 00119 std::string body; 00120 getline(log_, line); 00121 00122 qt_mf_msg msg("", category, application, 0, tv); 00123 msg.setSeverityLevel(sev); 00124 msg.setEventID(eventID); 00125 00126 while (!log_.eof() && line.find("%MSG") == std::string::npos) { 00127 body += line; 00128 getline(log_, line); 00129 } 00130 00131 msg.setMessage(filename_, counter_, body); 00132 msg.updateText(); 00133 00134 return msg; 00135 } 00136 00137 #include "moc_LogReader_receiver.cpp" 00138 00139 DEFINE_MFVIEWER_RECEIVER(mfviewer::LogReader)