Skip to content

Commit f942e82

Browse files
ehellbardavidrohr
authored andcommitted
Assign proper InfoLogger log level to ROOT log messages from stderr
1 parent 8486282 commit f942e82

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

Utilities/EPNMonitoring/src/EPNstderrMonitor.cxx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,16 @@ class EPNMonitor
6868
private:
6969
void thread();
7070
void check_add_file(const std::string& filename);
71-
void sendLog(const std::string& file, const std::string& message);
71+
void sendLog(const std::string& file, const std::string& message,
72+
const InfoLogger::InfoLogger::Severity severity = InfoLogger::InfoLogger::Severity::Error, int level = 3);
7273

7374
bool mInfoLoggerActive;
7475
volatile bool mTerminate = false;
7576
std::thread mThread;
7677
std::unordered_map<std::string, fileMon> mFiles;
7778
std::string mPath;
7879
std::vector<std::regex> mFilters;
80+
std::unordered_map<std::string, std::pair<InfoLogger::InfoLogger::Severity, int>> mMapRootLogTypes;
7981
volatile unsigned int mRunNumber;
8082
std::string mPartition;
8183
unsigned int nLines = 0;
@@ -87,11 +89,18 @@ class EPNMonitor
8789
EPNMonitor::EPNMonitor(std::string path, bool infoLogger, int runNumber, std::string partition)
8890
{
8991
mFilters.emplace_back("^Info in <");
92+
mFilters.emplace_back("^Print in <");
9093
mFilters.emplace_back("^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6}");
9194
mFilters.emplace_back("^Warning in <Fit");
9295
mFilters.emplace_back("^Warning in <TGraph");
9396
mFilters.emplace_back("^Warning in <TInterpreter");
9497
mFilters.emplace_back("Dividing histograms with different labels");
98+
mMapRootLogTypes.emplace("Info in <", std::pair<InfoLogger::InfoLogger::Severity, int>{InfoLogger::InfoLogger::Severity::Info, 13});
99+
mMapRootLogTypes.emplace("Print in <", std::pair<InfoLogger::InfoLogger::Severity, int>{InfoLogger::InfoLogger::Severity::Info, 13});
100+
mMapRootLogTypes.emplace("Warning in <", std::pair<InfoLogger::InfoLogger::Severity, int>{InfoLogger::InfoLogger::Severity::Warning, 11});
101+
mMapRootLogTypes.emplace("Error in <", std::pair<InfoLogger::InfoLogger::Severity, int>{InfoLogger::InfoLogger::Severity::Error, 2});
102+
mMapRootLogTypes.emplace("Fatal in <", std::pair<InfoLogger::InfoLogger::Severity, int>{InfoLogger::InfoLogger::Severity::Fatal, 1});
103+
mMapRootLogTypes.emplace("*** Break ***", std::pair<InfoLogger::InfoLogger::Severity, int>{InfoLogger::InfoLogger::Severity::Fatal, 1});
95104
mInfoLoggerActive = infoLogger;
96105
mPath = path;
97106
mRunNumber = runNumber;
@@ -120,15 +129,15 @@ void EPNMonitor::check_add_file(const std::string& filename)
120129
}
121130
}
122131

123-
void EPNMonitor::sendLog(const std::string& file, const std::string& message)
132+
void EPNMonitor::sendLog(const std::string& file, const std::string& message, const InfoLogger::InfoLogger::Severity severity, int level)
124133
{
125134
if (mInfoLoggerActive) {
126135
mLoggerContext->setField(InfoLogger::InfoLoggerContext::FieldName::Facility, ("stderr/" + file).substr(0, 31));
127136
mLoggerContext->setField(InfoLogger::InfoLoggerContext::FieldName::Run, mRunNumber != 0 ? std::to_string(mRunNumber) : "unspecified");
128-
static const InfoLogger::InfoLogger::InfoLoggerMessageOption opt = {InfoLogger::InfoLogger::Severity::Error, 3, InfoLogger::InfoLogger::undefinedMessageOption.errorCode, InfoLogger::InfoLogger::undefinedMessageOption.sourceFile, InfoLogger::InfoLogger::undefinedMessageOption.sourceLine};
137+
static const InfoLogger::InfoLogger::InfoLoggerMessageOption opt = {severity, level, InfoLogger::InfoLogger::undefinedMessageOption.errorCode, InfoLogger::InfoLogger::undefinedMessageOption.sourceFile, InfoLogger::InfoLogger::undefinedMessageOption.sourceLine};
129138
mLogger->log(opt, *mLoggerContext, "stderr: %s", file == "SYSLOG" ? (std::string("[GLOBAL SYSLOG]: ") + message).c_str() : message.c_str());
130139
} else {
131-
printf("stderr: %s: %s\n", file.c_str(), message.c_str());
140+
printf("stderr: [%c] %s: %s\n", severity, file.c_str(), message.c_str());
132141
}
133142
}
134143

@@ -202,6 +211,16 @@ void EPNMonitor::thread()
202211
if (filterLine) {
203212
continue;
204213
}
214+
// assign proper severity / level for remaining ROOT log messages
215+
auto severity{InfoLogger::InfoLogger::Severity::Error};
216+
int level{3};
217+
for (const auto& logType : mMapRootLogTypes) {
218+
if (line.find(logType.first) != std::string::npos) {
219+
severity = std::get<InfoLogger::InfoLogger::Severity>(logType.second);
220+
level = std::get<int>(logType.second);
221+
break;
222+
}
223+
}
205224
f.nLines++;
206225
f.nBytes += line.size();
207226
nLines++;
@@ -214,7 +233,7 @@ void EPNMonitor::thread()
214233
if (nLines >= MAX_LINES_TOTAL || nBytes >= MAX_BYTES_TOTAL) {
215234
break;
216235
}
217-
sendLog(f.name, line);
236+
sendLog(f.name, line, severity, level);
218237
}
219238
} while (!file.eof());
220239
}

0 commit comments

Comments
 (0)