Project
Loading...
Searching...
No Matches
LogParsingHelpers.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
12#include <regex>
13
14namespace o2::framework
15{
16
17char const* const LogParsingHelpers::LOG_LEVELS[(int)LogParsingHelpers::LogLevel::Size] = {
18 "DEBUG",
19 "INFO",
20 "WARNING",
21 "ALARM",
22 "ERROR",
23 "FATAL",
24 "UNKNOWN"};
26
28{
29
30 // Example format: [99:99:99][ERROR] (string begins with that, longest is 17 chars)
31 constexpr size_t MAXPREFLEN = 17;
32 constexpr size_t LABELPOS = 10;
33 if (s.size() < MAXPREFLEN && s.find("*** Break ***") == std::string::npos && !s.starts_with("[INFO]")) {
34 return LogLevel::Unknown;
35 }
36
37 // Check if first chars match [NN:NN:NN]
38 // 0123456789
39 if ((unsigned char)s[0] != '[' || (unsigned char)s[9] != ']' ||
40 (unsigned char)s[3] != ':' || (unsigned char)s[6] != ':' ||
41 (unsigned char)s[1] - '0' > 9 || (unsigned char)s[2] - '0' > 9 ||
42 (unsigned char)s[4] - '0' > 9 || (unsigned char)s[5] - '0' > 9 ||
43 (unsigned char)s[7] - '0' > 9 || (unsigned char)s[8] - '0' > 9) {
44 if (s.starts_with("Info in <") || s.starts_with("Print in <") || s.starts_with("[INFO]")) {
45 return LogLevel::Info;
46 } else if (s.starts_with("Warning in <")) {
47 return LogLevel::Warning;
48 } else if (s.find("Error in <") != std::string::npos) {
49 return LogLevel::Error;
50 } else if (s.starts_with("Fatal in <") || s.find("*** Break ***") != std::string::npos) {
51 return LogLevel::Fatal;
52 } else {
53 return LogLevel::Unknown;
54 }
55 }
56
57 if (s.compare(LABELPOS, 8, "[DEBUG] ") == 0) {
58 return LogLevel::Debug;
59 } else if (s.compare(LABELPOS, 7, "[INFO] ") == 0 ||
60 s.compare(LABELPOS, 8, "[STATE] ") == 0) {
61 return LogLevel::Info;
62 } else if (s.compare(LABELPOS, 7, "[WARN] ") == 0) {
63 return LogLevel::Warning;
64 } else if (s.compare(LABELPOS, 8, "[ALARM] ") == 0) {
65 return LogLevel::Alarm;
66 } else if (s.compare(LABELPOS, 8, "[ERROR] ") == 0) {
67 return LogLevel::Error;
68 } else if (s.compare(LABELPOS, 8, "[FATAL] ") == 0) {
69 return LogLevel::Fatal;
70 }
71 return LogLevel::Unknown;
72}
73} // namespace o2
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
LogLevel
Possible log levels for device log entries.
static LogLevel parseTokenLevel(std::string_view const s)
static char const *const LOG_LEVELS[(int) LogLevel::Size]
Available log levels.