Skip to content

Commit 6ff0ded

Browse files
committed
DPL: display stderr ROOT logs in the terminal output according to their proper log level
1 parent a830b62 commit 6ff0ded

File tree

5 files changed

+54
-21
lines changed

5 files changed

+54
-21
lines changed

Framework/Core/include/Framework/DeviceInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ struct DeviceInfo {
4545
size_t historySize;
4646
/// The maximum log level ever seen by this device
4747
LogParsingHelpers::LogLevel maxLogLevel;
48+
/// The minimum log level for log messages sent/displayed by this device
49+
LogParsingHelpers::LogLevel logLevel{LogParsingHelpers::LogLevel::Info};
4850

4951
/// The minimum level after which the device will exit with 0
5052
LogParsingHelpers::LogLevel minFailureLevel;

Framework/Core/include/Framework/LogParsingHelpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#ifndef O2_FRAMEWORK_LOGPARSINGHELPERS_H_
1212
#define O2_FRAMEWORK_LOGPARSINGHELPERS_H_
1313

14+
#include <map>
1415
#include <string>
1516
#include <string_view>
1617

@@ -34,6 +35,9 @@ struct LogParsingHelpers {
3435
/// Available log levels
3536
static char const* const LOG_LEVELS[(int)LogLevel::Size];
3637

38+
/// Map from ROOT log string to log level
39+
static const std::map<std::string, LogLevel> MAP_ROOT_LOG_LEVELS;
40+
3741
/// Extract the log style from a log string @param s
3842
/// Token style can then be used for colouring the logs
3943
/// in the GUI or to exit with error if a sufficient

Framework/Core/src/LogParsingHelpers.cxx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,23 @@ char const* const LogParsingHelpers::LOG_LEVELS[(int)LogParsingHelpers::LogLevel
2424
"UNKNOWN"};
2525
using LogLevel = o2::framework::LogParsingHelpers::LogLevel;
2626

27+
const std::map<std::string, LogLevel> LogParsingHelpers::MAP_ROOT_LOG_LEVELS = {
28+
{"[INFO]", LogLevel::Info},
29+
{"Print in <", LogLevel::Info},
30+
{"Info in <", LogLevel::Info},
31+
{"Warning in <", LogLevel::Warning},
32+
{"Error in <", LogLevel::Error},
33+
{"SysError in <", LogLevel::Error},
34+
{"Fatal in <", LogLevel::Fatal},
35+
{"*** Break ***", LogLevel::Fatal}};
36+
2737
LogLevel LogParsingHelpers::parseTokenLevel(std::string_view const s)
2838
{
2939

3040
// Example format: [99:99:99][ERROR] (string begins with that, longest is 17 chars)
3141
constexpr size_t MAXPREFLEN = 17;
3242
constexpr size_t LABELPOS = 10;
33-
if (s.size() < MAXPREFLEN) {
43+
if (s.size() < MAXPREFLEN && s.find("*** Break ***") == std::string::npos && !s.starts_with("[INFO]")) {
3444
return LogLevel::Unknown;
3545
}
3646

@@ -41,6 +51,11 @@ LogLevel LogParsingHelpers::parseTokenLevel(std::string_view const s)
4151
(unsigned char)s[1] - '0' > 9 || (unsigned char)s[2] - '0' > 9 ||
4252
(unsigned char)s[4] - '0' > 9 || (unsigned char)s[5] - '0' > 9 ||
4353
(unsigned char)s[7] - '0' > 9 || (unsigned char)s[8] - '0' > 9) {
54+
for (const auto& level : LogParsingHelpers::MAP_ROOT_LOG_LEVELS) {
55+
if (s.find(level.first) != std::string::npos) {
56+
return level.second;
57+
}
58+
}
4459
return LogLevel::Unknown;
4560
}
4661

Framework/Core/src/runDataProcessing.cxx

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,7 @@ void processChildrenOutput(uv_loop_t* loop,
884884
throw runtime_error("stdout is not supported anymore as a driver backend. Please use ws://");
885885
} else if (logLevel == LogParsingHelpers::LogLevel::Info && DeviceConfigHelper::parseConfig(token.substr(16), configMatch)) {
886886
throw runtime_error("stdout is not supported anymore as a driver backend. Please use ws://");
887-
} else if (!control.quiet && (token.find(control.logFilter) != std::string::npos) &&
888-
logLevel >= control.logLevel) {
887+
} else if (!control.quiet && (token.find(control.logFilter) != std::string::npos) && logLevel >= info.logLevel) {
889888
assert(info.historyPos >= 0);
890889
assert(info.historyPos < info.history.size());
891890
info.history[info.historyPos] = token;
@@ -2126,6 +2125,37 @@ int runStateMachine(DataProcessorSpecs const& workflow,
21262125
driverInfo.resourcesMonitoringDumpInterval * 1000,
21272126
driverInfo.resourcesMonitoringDumpInterval * 1000);
21282127
}
2128+
/// Set the value for the severity of displayed logs to the command line value --severity
2129+
for (const auto& processorInfo : dataProcessorInfos) {
2130+
const auto& cmdLineArgs = processorInfo.cmdLineArgs;
2131+
if (std::find(cmdLineArgs.begin(), cmdLineArgs.end(), "--severity") != cmdLineArgs.end()) {
2132+
for (size_t counter = 0; const auto& spec : runningWorkflow.devices) {
2133+
if (spec.name.compare(processorInfo.name) == 0) {
2134+
auto& info = infos[counter];
2135+
const auto logLevelIt = std::find(cmdLineArgs.begin(), cmdLineArgs.end(), "--severity") + 1;
2136+
if ((*logLevelIt).compare("debug") == 0) {
2137+
info.logLevel = LogParsingHelpers::LogLevel::Debug;
2138+
} else if ((*logLevelIt).compare("detail") == 0) {
2139+
info.logLevel = LogParsingHelpers::LogLevel::Debug;
2140+
} else if ((*logLevelIt).compare("info") == 0) {
2141+
info.logLevel = LogParsingHelpers::LogLevel::Info;
2142+
} else if ((*logLevelIt).compare("warning") == 0) {
2143+
info.logLevel = LogParsingHelpers::LogLevel::Warning;
2144+
} else if ((*logLevelIt).compare("error") == 0) {
2145+
info.logLevel = LogParsingHelpers::LogLevel::Error;
2146+
} else if ((*logLevelIt).compare("important") == 0) {
2147+
info.logLevel = LogParsingHelpers::LogLevel::Info;
2148+
} else if ((*logLevelIt).compare("alarm") == 0) {
2149+
info.logLevel = LogParsingHelpers::LogLevel::Alarm;
2150+
} else if ((*logLevelIt).compare("fatal") == 0) {
2151+
info.logLevel = LogParsingHelpers::LogLevel::Fatal;
2152+
}
2153+
break;
2154+
}
2155+
++counter;
2156+
}
2157+
}
2158+
}
21292159
LOG(info) << "Redeployment of configuration done.";
21302160
} break;
21312161
case DriverState::RUNNING:

Framework/GUISupport/src/FrameworkGUIDebugger.cxx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,6 @@ void displayHistory(const DeviceInfo& info, DeviceControl& control)
142142
auto& line = info.history[ji];
143143
auto logLevel = info.historyLevel[ji];
144144

145-
// assign proper loglevel to ROOT log messages from stderr
146-
auto getLogLevelUnknown = [&line]() -> LogParsingHelpers::LogLevel {
147-
if (line.starts_with("Print in") || line.starts_with("Info in") || line.starts_with("[INFO]")) {
148-
return LogParsingHelpers::LogLevel::Info;
149-
} else if (line.starts_with("Warning in")) {
150-
return LogParsingHelpers::LogLevel::Warning;
151-
} else if (line.starts_with("Error in") || line.starts_with("SysError in")) {
152-
return LogParsingHelpers::LogLevel::Error;
153-
} else if (line.starts_with("Fatal in") || line.starts_with("*** Break ***")) {
154-
return LogParsingHelpers::LogLevel::Fatal;
155-
} else {
156-
return LogParsingHelpers::LogLevel::Unknown;
157-
}
158-
};
159-
if (logLevel == LogParsingHelpers::LogLevel::Unknown) {
160-
logLevel = getLogLevelUnknown();
161-
}
162-
163145
// Skip empty lines
164146
if (line.empty()) {
165147
ji = (ji + 1) % historySize;

0 commit comments

Comments
 (0)