Skip to content

Commit 25cbb2a

Browse files
committed
DPL: assign proper log level for ROOT log messages from stderr in terminal output
1 parent 0fb7a09 commit 25cbb2a

File tree

4 files changed

+45
-19
lines changed

4 files changed

+45
-19
lines changed

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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,24 @@ 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+
{" *** Break ***", LogLevel::Fatal}};
37+
2738
LogLevel LogParsingHelpers::parseTokenLevel(std::string_view const s)
2839
{
2940

3041
// Example format: [99:99:99][ERROR] (string begins with that, longest is 17 chars)
3142
constexpr size_t MAXPREFLEN = 17;
3243
constexpr size_t LABELPOS = 10;
33-
if (s.size() < MAXPREFLEN) {
44+
if (s.size() < MAXPREFLEN && s.find("*** Break ***") == std::string::npos && s.compare("[INFO]") != 0) {
3445
return LogLevel::Unknown;
3546
}
3647

@@ -41,6 +52,11 @@ LogLevel LogParsingHelpers::parseTokenLevel(std::string_view const s)
4152
(unsigned char)s[1] - '0' > 9 || (unsigned char)s[2] - '0' > 9 ||
4253
(unsigned char)s[4] - '0' > 9 || (unsigned char)s[5] - '0' > 9 ||
4354
(unsigned char)s[7] - '0' > 9 || (unsigned char)s[8] - '0' > 9) {
55+
for (const auto& level : LogParsingHelpers::MAP_ROOT_LOG_LEVELS) {
56+
if (s.starts_with(level.first)) {
57+
return level.second;
58+
}
59+
}
4460
return LogLevel::Unknown;
4561
}
4662

Framework/Core/src/runDataProcessing.cxx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,30 @@ int runStateMachine(DataProcessorSpecs const& workflow,
20162016
control.tracingFlags = tracingFlags;
20172017
}
20182018
}
2019+
/// Set the value for logging severity to the command line value --severity
2020+
if (varmap.count("severity")) {
2021+
auto logLevel = varmap["severity"].as<std::string>();
2022+
for (auto& control : controls) {
2023+
if (logLevel == "debug") {
2024+
control.logLevel = LogParsingHelpers::LogLevel::Debug;
2025+
} else if (logLevel == "detail") {
2026+
control.logLevel = LogParsingHelpers::LogLevel::Debug;
2027+
} else if (logLevel == "info") {
2028+
control.logLevel = LogParsingHelpers::LogLevel::Info;
2029+
} else if (logLevel == "warning") {
2030+
control.logLevel = LogParsingHelpers::LogLevel::Warning;
2031+
} else if (logLevel == "error") {
2032+
control.logLevel = LogParsingHelpers::LogLevel::Error;
2033+
} else if (logLevel == "important") {
2034+
control.logLevel = LogParsingHelpers::LogLevel::Info;
2035+
} else if (logLevel == "alarm") {
2036+
control.logLevel = LogParsingHelpers::LogLevel::Alarm;
2037+
} else if (logLevel == "fatal") {
2038+
control.logLevel = LogParsingHelpers::LogLevel::Fatal;
2039+
}
2040+
}
2041+
}
2042+
20192043
deviceExecutions.resize(runningWorkflow.devices.size());
20202044

20212045
// Options which should be uniform across all

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)