1 #include "mfextensions/Receivers/LogReader_receiver.hh"
2 #include "mfextensions/Receivers/ReceiverMacros.hh"
5 mfviewer::LogReader::LogReader(fhicl::ParameterSet pset)
9 , filename_(pset.get<std::string>(
"filename"))
12 (
"\\%MSG-([wide])\\s([^:]*):\\s\\s([^\\s]*)\\s*(\\d\\d-[^-]*-\\d{4}\\s\\d+:\\d+:\\d+)\\s.[DS]T\\s\\s(\\w+)")
16 std::cout <<
"LogReader_receiver Constructor" << std::endl;
19 mfviewer::LogReader::~LogReader()
24 void mfviewer::LogReader::run()
26 while (!stopRequested_)
28 log_.open(filename_.c_str(), std::fstream::in);
31 if (log_.is_open() && log_.good())
33 bool msgFound =
false;
44 if (line.find(
"%MSG") != std::string::npos)
53 std::cout <<
"Message found, emitting!" << std::endl;
54 emit NewMessage(read_next());
67 std::cout <<
"LogReader_receiver shutting down!" << std::endl;
74 mf::MessageFacilityMsg mfviewer::LogReader::read_next()
76 mf::MessageFacilityMsg msg;
82 if (boost::regex_search(line, what_, metadata_1))
85 std::cout <<
">> " << std::string(what_[1].first, what_[1].second) <<
"\n";
86 std::cout <<
">> " << std::string(what_[2].first, what_[2].second) <<
"\n";
87 std::cout <<
">> " << std::string(what_[3].first, what_[3].second) <<
"\n";
88 std::cout <<
">> " << std::string(what_[4].first, what_[4].second) <<
"\n";
89 std::cout <<
">> " << std::string(what_[5].first, what_[5].second) <<
"\n";
92 std::string value = std::string(what_[1].first, what_[1].second);
96 case 'e': msg.setSeverity(
"ERROR");
98 case 'w': msg.setSeverity(
"WARNING");
100 case 'i': msg.setSeverity(
"INFO");
102 case 'd': msg.setSeverity(
"DEBUG");
111 value = std::string(what_[4].first, what_[4].second);
112 strptime(value.c_str(),
"%d-%b-%Y %H:%M:%S", &tm);
119 msg.setCategory(std::string(what_[2].first, what_[2].second));
120 msg.setTimestamp(tv);
121 msg.setApplication(std::string(what_[3].first, what_[3].second));
122 # if MESSAGEFACILITY_HEX_VERSION >= 0x20002 // an indication of a switch from s48 to s50
123 msg.setModule(std::string(what_[5].first, what_[5].second));
125 msg.setProcess(std::string(what_[5].first, what_[5].second));
133 while (!log_.eof() && line.find(
"%MSG") == std::string::npos)
139 msg.setMessage(filename_, std::to_string(counter_), body);
142 "Time: " << msg.timestr() <<
143 ", Severity: " << msg.severity() <<
144 ", Category: " << msg.category() <<
145 ", Hostname: " << msg.hostname() <<
146 ", Hostaddr: " << msg.hostaddr() <<
147 # if MESSAGEFACILITY_HEX_VERSION < 0x20002 // v2_00_02 is s50, pre v2_00_02 is s48
148 ", Process: " << msg.process() <<
150 ", Application: " << msg.application() <<
151 ", Module: " << msg.module() <<
152 ", Context: " << msg.context() <<
153 ", File: " << msg.file() <<
154 ", Message: " << msg.message() << std::endl;
159 #include "moc_LogReader_receiver.cpp"
MessageFacility Log Reader Read messagefacility log archive and reemit as messagefacility messages ...