From 27527ad87b63213b7c58caf1e34a538e76f273da Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Tue, 4 Feb 2025 10:31:32 +0100 Subject: [PATCH] Add critical severity level between fatal and error --- README.md | 1 + logger/Logger.cxx | 7 +++++-- logger/Logger.h | 7 ++++--- test/cycle.cxx | 6 +++--- test/logger.cxx | 1 + test/nolog.cxx | 1 + test/severity.cxx | 1 + 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d7dd73d..1f209bf 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ where severity level is one of the following: "important", "alarm", "error", +"critical", "fatal", ``` diff --git a/logger/Logger.cxx b/logger/Logger.cxx index 3d6cd3e..28704df 100644 --- a/logger/Logger.cxx +++ b/logger/Logger.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2025 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -69,6 +69,7 @@ const unordered_map Logger::fSeverityMap = { {"NOLOG"}, Severity::nolog }, { {"fatal"}, Severity::fatal }, { {"FATAL"}, Severity::fatal }, + { {"critical"}, Severity::critical }, { {"error"}, Severity::error }, { {"ERROR"}, Severity::error }, { {"alarm"}, Severity::alarm }, @@ -96,7 +97,7 @@ const unordered_map Logger::fSeverityMap = { {"TRACE"}, Severity::trace } }; -const array Logger::fSeverityNames = +const array Logger::fSeverityNames = { { "NOLOG", @@ -113,6 +114,7 @@ const array Logger::fSeverityNames = "IMPORTANT", "ALARM", "ERROR", + "CRITICAL", "FATAL" } }; @@ -289,6 +291,7 @@ string Logger::GetColoredSeverityString(Severity severity) switch (severity) { case Severity::nolog: return "\033[01;39mNOLOG\033[0m"; break; case Severity::fatal: return "\033[01;31mFATAL\033[0m"; break; + case Severity::critical: return "\033[01;31mCRITICAL\033[0m"; break; case Severity::error: return "\033[01;31mERROR\033[0m"; break; case Severity::alarm: return "\033[01;33mALARM\033[0m"; break; case Severity::important: return "\033[01;32mIMPORTANT\033[0m"; break; diff --git a/logger/Logger.h b/logger/Logger.h index a49501d..42e83d4 100644 --- a/logger/Logger.h +++ b/logger/Logger.h @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2014-2019 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2014-2025 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -67,7 +67,8 @@ enum class Severity : int important = 11, alarm = 12, error = 13, - fatal = 14, + critical = 14, + fatal = 15, // aliases warning = warn, // backwards-compatibility @@ -325,7 +326,7 @@ class Logger static const std::unordered_map fVerbosityMap; static const std::unordered_map fSeverityMap; - static const std::array fSeverityNames; + static const std::array fSeverityNames; static const std::array fVerbosityNames; // protection for use after static destruction took place diff --git a/test/cycle.cxx b/test/cycle.cxx index 9c16ef4..79bdb62 100644 --- a/test/cycle.cxx +++ b/test/cycle.cxx @@ -1,5 +1,5 @@ /******************************************************************************** - * Copyright (C) 2015-2020 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * + * Copyright (C) 2015-2025 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * * * This software is distributed under the terms of the * * GNU Lesser General Public Licence (LGPL) version 3, * @@ -38,7 +38,7 @@ int main() Logger::SetConsoleSeverity(Severity::fatal); cout << "initial severity >" << Logger::GetConsoleSeverity() << "<" << endl << endl; - array severitiesUp{{ Severity::nolog, Severity::trace, Severity::debug4, Severity::debug3, Severity::debug2, Severity::debug1, Severity::debug, Severity::detail, Severity::info, Severity::state, Severity::warn, Severity::important, Severity::alarm, Severity::error, Severity::fatal }}; + array severitiesUp{{ Severity::nolog, Severity::trace, Severity::debug4, Severity::debug3, Severity::debug2, Severity::debug1, Severity::debug, Severity::detail, Severity::info, Severity::state, Severity::warn, Severity::important, Severity::alarm, Severity::error, Severity::critical, Severity::fatal }}; #ifdef FAIR_MIN_SEVERITY for (unsigned int i = static_cast(Severity::FAIR_MIN_SEVERITY); i < severitiesUp.size(); ++i) { #else @@ -57,7 +57,7 @@ int main() Logger::SetConsoleSeverity(Severity::fatal); cout << "initial severity >" << Logger::GetConsoleSeverity() << "<" << endl << endl; - array severitiesDown{{ Severity::error, Severity::alarm, Severity::important, Severity::warn, Severity::state, Severity::info, Severity::detail, Severity::debug, Severity::debug1, Severity::debug2, Severity::debug3, Severity::debug4, Severity::trace, Severity::nolog, Severity::fatal }}; + array severitiesDown{{ Severity::critical, Severity::error, Severity::alarm, Severity::important, Severity::warn, Severity::state, Severity::info, Severity::detail, Severity::debug, Severity::debug1, Severity::debug2, Severity::debug3, Severity::debug4, Severity::trace, Severity::nolog, Severity::fatal }}; #ifdef FAIR_MIN_SEVERITY for (unsigned int i = 0; i < severitiesDown.size() - static_cast(Severity::FAIR_MIN_SEVERITY) - 1; ++i) { #else diff --git a/test/logger.cxx b/test/logger.cxx index 6ef1fbe..666da23 100644 --- a/test/logger.cxx +++ b/test/logger.cxx @@ -31,6 +31,7 @@ void printEverySeverity() LOG(important) << "important message, counter: " << i++; LOG(alarm) << "alarm message, counter: " << i++; LOG(error) << "error message, counter: " << i++; + LOG(critical) << "critical message, counter: " << i++; LOG(fatal) << "fatal message, counter: " << i++; } diff --git a/test/nolog.cxx b/test/nolog.cxx index c8c5f3a..13e992c 100644 --- a/test/nolog.cxx +++ b/test/nolog.cxx @@ -27,6 +27,7 @@ void printEverySeverity() LOG(important) << "important message "; LOG(alarm) << "alarm message "; LOG(error) << "error message "; + LOG(critical) << "critical message "; } void silentlyPrintAllVerbositiesWithSeverity(Severity sev) diff --git a/test/severity.cxx b/test/severity.cxx index 99e0f64..053a502 100644 --- a/test/severity.cxx +++ b/test/severity.cxx @@ -34,6 +34,7 @@ uint32_t printEverySeverity(uint32_t i) LOG(important) << "important message, counter: " << i++; LOG(alarm) << "alarm message, counter: " << i++; LOG(error) << "error message, counter: " << i++; + LOG(critical) << "critical message, counter: " << i++; LOG(fatal) << "fatal message, counter: " << i++; return i;