Compare commits

..

9 Commits

Author SHA1 Message Date
Alexey Rybalchenko
56b90a7445 Avoid "Unknown severity" message also for uppercase fatal 2022-06-28 11:23:57 +02:00
Giulio Eulisse
7fc05f3808 Avoid "Unknown severity" message for fatal 2022-06-28 11:23:57 +02:00
Dennis Klein
d93fb0870b ci: Update macOS builds 2022-04-17 06:10:15 +02:00
Alexey Rybalchenko
953eac19c8 Add 'detail' severity between debug and info 2022-04-12 11:00:41 +02:00
Alexey Rybalchenko
9a6644c931 Adapt to fmt's deprecation of format_to memory buffer overload 2021-11-26 11:23:42 +01:00
Alexey Rybalchenko
27040ea292 Deprecate uppercase severity names 2021-11-25 14:29:18 +01:00
David Rohr
6545d0efa2 Include fmt/ostream.h, needed for on the fly std::ostream usage 2021-11-15 10:52:33 +01:00
Dennis Klein
159a21c24b ci: Add macos-11-arm64 (apple-clang-13) build 2021-10-01 17:10:13 +02:00
Dennis Klein
2494a9e85a Revert "Deprecate uppercase severity names"
This reverts commit ba7da2f79a.
2021-09-21 12:54:42 +02:00
8 changed files with 68 additions and 55 deletions

3
Jenkinsfile vendored
View File

@@ -62,7 +62,8 @@ pipeline{
[os: 'fedora', ver: '32', arch: 'x86_64', compiler: 'gcc-10'], [os: 'fedora', ver: '32', arch: 'x86_64', compiler: 'gcc-10'],
[os: 'fedora', ver: '33', arch: 'x86_64', compiler: 'gcc-10'], [os: 'fedora', ver: '33', arch: 'x86_64', compiler: 'gcc-10'],
[os: 'fedora', ver: '34', arch: 'x86_64', compiler: 'gcc-11'], [os: 'fedora', ver: '34', arch: 'x86_64', compiler: 'gcc-11'],
[os: 'macos', ver: '11', arch: 'x86_64', compiler: 'apple-clang-12'], [os: 'macos', ver: '12', arch: 'x86_64', compiler: 'apple-clang-13'],
[os: 'macos', ver: '12', arch: 'arm64', compiler: 'apple-clang-13'],
]) ])
parallel(builds) parallel(builds)

View File

@@ -93,6 +93,7 @@ where severity level is one of the following:
"debug2", "debug2",
"debug1", "debug1",
"debug", "debug",
"detail",
"info", "info",
"state", "state",
"warn", "warn",

View File

@@ -15,6 +15,7 @@
#include <cstdio> // printf #include <cstdio> // printf
#include <iostream> #include <iostream>
#include <iterator> // std::back_inserter
using namespace std; using namespace std;
@@ -65,6 +66,8 @@ const unordered_map<string, Severity> Logger::fSeverityMap =
{ {
{ "nolog", Severity::nolog }, { "nolog", Severity::nolog },
{ "NOLOG", Severity::nolog }, { "NOLOG", Severity::nolog },
{ "fatal", Severity::fatal },
{ "FATAL", Severity::fatal },
{ "error", Severity::error }, { "error", Severity::error },
{ "ERROR", Severity::error }, { "ERROR", Severity::error },
{ "alarm", Severity::alarm }, { "alarm", Severity::alarm },
@@ -77,6 +80,7 @@ const unordered_map<string, Severity> Logger::fSeverityMap =
{ "STATE", Severity::state }, { "STATE", Severity::state },
{ "info", Severity::info }, { "info", Severity::info },
{ "INFO", Severity::info }, { "INFO", Severity::info },
{ "detail", Severity::detail },
{ "debug", Severity::debug }, { "debug", Severity::debug },
{ "DEBUG", Severity::debug }, { "DEBUG", Severity::debug },
{ "debug1", Severity::debug1 }, { "debug1", Severity::debug1 },
@@ -91,7 +95,7 @@ const unordered_map<string, Severity> Logger::fSeverityMap =
{ "TRACE", Severity::trace } { "TRACE", Severity::trace }
}; };
const array<string, 14> Logger::fSeverityNames = const array<string, 15> Logger::fSeverityNames =
{ {
{ {
"NOLOG", "NOLOG",
@@ -101,6 +105,7 @@ const array<string, 14> Logger::fSeverityNames =
"DEBUG2", "DEBUG2",
"DEBUG1", "DEBUG1",
"DEBUG", "DEBUG",
"DETAIL",
"INFO", "INFO",
"STATE", "STATE",
"WARN", "WARN",
@@ -160,27 +165,27 @@ Logger::Logger(Severity severity, Verbosity verbosity, const string& file, const
for (const auto info : spec.fInfos) { for (const auto info : spec.fInfos) {
switch (info) { switch (info) {
case VSpec::Info::process_name: case VSpec::Info::process_name:
fmt::format_to(fBWPrefix, "[{}]", fInfos.process_name); fmt::format_to(std::back_inserter(fBWPrefix), "[{}]", fInfos.process_name);
break; break;
case VSpec::Info::timestamp_us: case VSpec::Info::timestamp_us:
FillTimeInfos(); FillTimeInfos();
fmt::format_to(fBWPrefix, "[{:%H:%M:%S}.{:06}]", fmt::localtime(fInfos.timestamp), fInfos.us.count()); fmt::format_to(std::back_inserter(fBWPrefix), "[{:%H:%M:%S}.{:06}]", fmt::localtime(fInfos.timestamp), fInfos.us.count());
break; break;
case VSpec::Info::timestamp_s: case VSpec::Info::timestamp_s:
FillTimeInfos(); FillTimeInfos();
fmt::format_to(fBWPrefix, "[{:%H:%M:%S}]", fmt::localtime(fInfos.timestamp)); fmt::format_to(std::back_inserter(fBWPrefix), "[{:%H:%M:%S}]", fmt::localtime(fInfos.timestamp));
break; break;
case VSpec::Info::severity: case VSpec::Info::severity:
fmt::format_to(fBWPrefix, "[{}]", fInfos.severity_name); fmt::format_to(std::back_inserter(fBWPrefix), "[{}]", fInfos.severity_name);
break; break;
case VSpec::Info::file_line_function: case VSpec::Info::file_line_function:
fmt::format_to(fBWPrefix, "[{}:{}:{}]", fInfos.file, fInfos.line, fInfos.func); fmt::format_to(std::back_inserter(fBWPrefix), "[{}:{}:{}]", fInfos.file, fInfos.line, fInfos.func);
break; break;
case VSpec::Info::file_line: case VSpec::Info::file_line:
fmt::format_to(fBWPrefix, "[{}:{}]", fInfos.file, fInfos.line); fmt::format_to(std::back_inserter(fBWPrefix), "[{}:{}]", fInfos.file, fInfos.line);
break; break;
case VSpec::Info::file: case VSpec::Info::file:
fmt::format_to(fBWPrefix, "[{}]", fInfos.file); fmt::format_to(std::back_inserter(fBWPrefix), "[{}]", fInfos.file);
break; break;
default: default:
break; break;
@@ -188,7 +193,7 @@ Logger::Logger(Severity severity, Verbosity verbosity, const string& file, const
} }
if (spec.fSize > 0) { if (spec.fSize > 0) {
fmt::format_to(fBWPrefix, " "); fmt::format_to(std::back_inserter(fBWPrefix), " ");
} }
} }
@@ -196,27 +201,27 @@ Logger::Logger(Severity severity, Verbosity verbosity, const string& file, const
for (const auto info : spec.fInfos) { for (const auto info : spec.fInfos) {
switch (info) { switch (info) {
case VSpec::Info::process_name: case VSpec::Info::process_name:
fmt::format_to(fColorPrefix, "[{}]", ColorOut(Color::fgBlue, fInfos.process_name)); fmt::format_to(std::back_inserter(fColorPrefix), "[{}]", ColorOut(Color::fgBlue, fInfos.process_name));
break; break;
case VSpec::Info::timestamp_us: case VSpec::Info::timestamp_us:
FillTimeInfos(); FillTimeInfos();
fmt::format_to(fColorPrefix, "[{}{:%H:%M:%S}.{:06}{}]", startColor(Color::fgCyan), fmt::localtime(fInfos.timestamp), fInfos.us.count(), endColor()); fmt::format_to(std::back_inserter(fColorPrefix), "[{}{:%H:%M:%S}.{:06}{}]", startColor(Color::fgCyan), fmt::localtime(fInfos.timestamp), fInfos.us.count(), endColor());
break; break;
case VSpec::Info::timestamp_s: case VSpec::Info::timestamp_s:
FillTimeInfos(); FillTimeInfos();
fmt::format_to(fColorPrefix, "[{}{:%H:%M:%S}{}]", startColor(Color::fgCyan), fmt::localtime(fInfos.timestamp), endColor()); fmt::format_to(std::back_inserter(fColorPrefix), "[{}{:%H:%M:%S}{}]", startColor(Color::fgCyan), fmt::localtime(fInfos.timestamp), endColor());
break; break;
case VSpec::Info::severity: case VSpec::Info::severity:
fmt::format_to(fColorPrefix, "[{}]", GetColoredSeverityString(fInfos.severity)); fmt::format_to(std::back_inserter(fColorPrefix), "[{}]", GetColoredSeverityString(fInfos.severity));
break; break;
case VSpec::Info::file_line_function: case VSpec::Info::file_line_function:
fmt::format_to(fColorPrefix, "[{}:{}:{}]", ColorOut(Color::fgBlue, fInfos.file), ColorOut(Color::fgYellow, fInfos.line), ColorOut(Color::fgBlue, fInfos.func)); fmt::format_to(std::back_inserter(fColorPrefix), "[{}:{}:{}]", ColorOut(Color::fgBlue, fInfos.file), ColorOut(Color::fgYellow, fInfos.line), ColorOut(Color::fgBlue, fInfos.func));
break; break;
case VSpec::Info::file_line: case VSpec::Info::file_line:
fmt::format_to(fColorPrefix, "[{}:{}]", ColorOut(Color::fgBlue, fInfos.file), ColorOut(Color::fgYellow, fInfos.line)); fmt::format_to(std::back_inserter(fColorPrefix), "[{}:{}]", ColorOut(Color::fgBlue, fInfos.file), ColorOut(Color::fgYellow, fInfos.line));
break; break;
case VSpec::Info::file: case VSpec::Info::file:
fmt::format_to(fColorPrefix, "[{}]", ColorOut(Color::fgBlue, fInfos.file)); fmt::format_to(std::back_inserter(fColorPrefix), "[{}]", ColorOut(Color::fgBlue, fInfos.file));
break; break;
default: default:
break; break;
@@ -224,7 +229,7 @@ Logger::Logger(Severity severity, Verbosity verbosity, const string& file, const
} }
if (spec.fSize > 0) { if (spec.fSize > 0) {
fmt::format_to(fColorPrefix, " "); fmt::format_to(std::back_inserter(fColorPrefix), " ");
} }
} }
@@ -290,6 +295,7 @@ string Logger::GetColoredSeverityString(Severity severity)
case Severity::warn: return "\033[01;33mWARN\033[0m"; break; case Severity::warn: return "\033[01;33mWARN\033[0m"; break;
case Severity::state: return "\033[01;35mSTATE\033[0m"; break; case Severity::state: return "\033[01;35mSTATE\033[0m"; break;
case Severity::info: return "\033[01;32mINFO\033[0m"; break; case Severity::info: return "\033[01;32mINFO\033[0m"; break;
case Severity::detail: return "\033[01;32mDETAIL\033[0m"; break;
case Severity::debug: return "\033[01;34mDEBUG\033[0m"; break; case Severity::debug: return "\033[01;34mDEBUG\033[0m"; break;
case Severity::debug1: return "\033[01;34mDEBUG1\033[0m"; break; case Severity::debug1: return "\033[01;34mDEBUG1\033[0m"; break;
case Severity::debug2: return "\033[01;34mDEBUG2\033[0m"; break; case Severity::debug2: return "\033[01;34mDEBUG2\033[0m"; break;

View File

@@ -26,6 +26,7 @@
#include <fmt/core.h> #include <fmt/core.h>
#include <fmt/printf.h> #include <fmt/printf.h>
#include <fmt/ostream.h>
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
@@ -58,29 +59,30 @@ enum class Severity : int
debug2 = 4, debug2 = 4,
debug1 = 5, debug1 = 5,
debug = 6, debug = 6,
info = 7, detail = 7,
state = 8, info = 8,
warn = 9, state = 9,
important = 10, warn = 10,
alarm = 11, important = 11,
error = 12, alarm = 12,
fatal = 13, error = 13,
fatal = 14,
// aliases // aliases
warning = warn, warning = warn,
// backwards-compatibility // backwards-compatibility
NOLOG [[deprecated("Use 'nolog' instead")]] = nolog, NOLOG __attribute__((deprecated("Use LOG(nolog) instead (lowercase severity name)."))) = nolog,
TRACE [[deprecated("Use 'trace' instead")]] = trace, FATAL __attribute__((deprecated("Use LOG(fatal) instead (lowercase severity name)."))) = fatal,
DEBUG4 [[deprecated("Use 'debug4' instead")]] = debug4, ERROR __attribute__((deprecated("Use LOG(error) instead (lowercase severity name)."))) = error,
DEBUG3 [[deprecated("Use 'debug3' instead")]] = debug3, WARN __attribute__((deprecated("Use LOG(warn) instead (lowercase severity name)."))) = warn,
DEBUG2 [[deprecated("Use 'debug2' instead")]] = debug2, WARNING __attribute__((deprecated("Use LOG(warning) instead (lowercase severity name)."))) = warn,
DEBUG1 [[deprecated("Use 'debug1' instead")]] = debug1, STATE __attribute__((deprecated("Use LOG(state) instead (lowercase severity name)."))) = state,
DEBUG [[deprecated("Use 'debug' instead")]] = debug, INFO __attribute__((deprecated("Use LOG(info) instead (lowercase severity name)."))) = info,
INFO [[deprecated("Use 'info' instead")]] = info, DEBUG __attribute__((deprecated("Use LOG(debug) instead (lowercase severity name)."))) = debug,
STATE [[deprecated("Use 'state' instead")]] = state, DEBUG1 __attribute__((deprecated("Use LOG(debug1) instead (lowercase severity name)."))) = debug1,
WARNING [[deprecated("Use 'warning' instead")]] = warn, DEBUG2 __attribute__((deprecated("Use LOG(debug2) instead (lowercase severity name)."))) = debug2,
WARN [[deprecated("Use 'warn' instead")]] = warn, DEBUG3 __attribute__((deprecated("Use LOG(debug3) instead (lowercase severity name)."))) = debug3,
ERROR [[deprecated("Use 'error' instead")]] = error, DEBUG4 __attribute__((deprecated("Use LOG(debug4) instead (lowercase severity name)."))) = debug4,
FATAL [[deprecated("Use 'fatal' instead")]] = fatal TRACE __attribute__((deprecated("Use LOG(trace) instead (lowercase severity name)."))) = trace
}; };
// verbosity levels: // verbosity levels:
@@ -322,7 +324,7 @@ class Logger
static const std::unordered_map<std::string, Verbosity> fVerbosityMap; static const std::unordered_map<std::string, Verbosity> fVerbosityMap;
static const std::unordered_map<std::string, Severity> fSeverityMap; static const std::unordered_map<std::string, Severity> fSeverityMap;
static const std::array<std::string, 14> fSeverityNames; static const std::array<std::string, 15> fSeverityNames;
static const std::array<std::string, 9> fVerbosityNames; static const std::array<std::string, 9> fVerbosityNames;
// protection for use after static destruction took place // protection for use after static destruction took place

View File

@@ -1,5 +1,5 @@
/******************************************************************************** /********************************************************************************
* Copyright (C) 2014-2020 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH * * Copyright (C) 2015-2020 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* * * *
* This software is distributed under the terms of the * * This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, * * GNU Lesser General Public Licence (LGPL) version 3, *
@@ -38,7 +38,7 @@ int main()
Logger::SetConsoleSeverity(Severity::fatal); Logger::SetConsoleSeverity(Severity::fatal);
cout << "initial severity >" << Logger::GetConsoleSeverity() << "<" << endl << endl; cout << "initial severity >" << Logger::GetConsoleSeverity() << "<" << endl << endl;
array<Severity, 14> severitiesUp{{ Severity::nolog, Severity::trace, Severity::debug4, Severity::debug3, Severity::debug2, Severity::debug1, Severity::debug, Severity::info, Severity::state, Severity::warn, Severity::important, Severity::alarm, Severity::error, Severity::fatal }}; array<Severity, 15> 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 }};
#ifdef FAIR_MIN_SEVERITY #ifdef FAIR_MIN_SEVERITY
for (unsigned int i = static_cast<int>(Severity::FAIR_MIN_SEVERITY); i < severitiesUp.size(); ++i) { for (unsigned int i = static_cast<int>(Severity::FAIR_MIN_SEVERITY); i < severitiesUp.size(); ++i) {
#else #else
@@ -57,7 +57,7 @@ int main()
Logger::SetConsoleSeverity(Severity::fatal); Logger::SetConsoleSeverity(Severity::fatal);
cout << "initial severity >" << Logger::GetConsoleSeverity() << "<" << endl << endl; cout << "initial severity >" << Logger::GetConsoleSeverity() << "<" << endl << endl;
array<Severity, 14> severitiesDown{{ Severity::error, Severity::alarm, Severity::important, Severity::warn, Severity::state, Severity::info, Severity::debug, Severity::debug1, Severity::debug2, Severity::debug3, Severity::debug4, Severity::trace, Severity::nolog, Severity::fatal }}; array<Severity, 15> 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 }};
#ifdef FAIR_MIN_SEVERITY #ifdef FAIR_MIN_SEVERITY
for (unsigned int i = 0; i < severitiesDown.size() - static_cast<int>(Severity::FAIR_MIN_SEVERITY) - 1; ++i) { for (unsigned int i = 0; i < severitiesDown.size() - static_cast<int>(Severity::FAIR_MIN_SEVERITY) - 1; ++i) {
#else #else

View File

@@ -24,6 +24,7 @@ void printEverySeverity()
LOG(debug2) << "debug2 message, counter: " << i++; LOG(debug2) << "debug2 message, counter: " << i++;
LOG(debug1) << "debug1 message, counter: " << i++; LOG(debug1) << "debug1 message, counter: " << i++;
LOG(debug) << "debug message, counter: " << i++; LOG(debug) << "debug message, counter: " << i++;
LOG(detail) << "detail message, counter: " << i++;
LOG(info) << "info message, counter: " << i++; LOG(info) << "info message, counter: " << i++;
LOG(state) << "state message, counter: " << i++; LOG(state) << "state message, counter: " << i++;
LOG(warn) << "warning message, counter: " << i++; LOG(warn) << "warning message, counter: " << i++;

View File

@@ -13,19 +13,20 @@ using namespace fair;
void printEverySeverity() void printEverySeverity()
{ {
LOG(nolog) << "nolog message, counter: "; LOG(nolog) << "nolog message ";
LOG(trace) << "trace message, counter: "; LOG(trace) << "trace message ";
LOG(debug4) << "debug4 message, counter: "; LOG(debug4) << "debug4 message ";
LOG(debug3) << "debug3 message, counter: "; LOG(debug3) << "debug3 message ";
LOG(debug2) << "debug2 message, counter: "; LOG(debug2) << "debug2 message ";
LOG(debug1) << "debug1 message, counter: "; LOG(debug1) << "debug1 message ";
LOG(debug) << "debug message, counter: "; LOG(debug) << "debug message ";
LOG(info) << "info message, counter: "; LOG(detail) << "detail message ";
LOG(state) << "state message, counter: "; LOG(info) << "info message ";
LOG(warn) << "warning message, counter: "; LOG(state) << "state message ";
LOG(important) << "important message, counter: "; LOG(warn) << "warning message ";
LOG(alarm) << "alarm message, counter: "; LOG(important) << "important message ";
LOG(error) << "error message, counter: "; LOG(alarm) << "alarm message ";
LOG(error) << "error message ";
} }
void silentlyPrintAllVerbositiesWithSeverity(Severity sev) void silentlyPrintAllVerbositiesWithSeverity(Severity sev)

View File

@@ -27,6 +27,7 @@ uint32_t printEverySeverity(uint32_t i)
LOG(debug2) << "debug2 message, counter: " << i++; LOG(debug2) << "debug2 message, counter: " << i++;
LOG(debug1) << "debug1 message, counter: " << i++; LOG(debug1) << "debug1 message, counter: " << i++;
LOG(debug) << "debug message, counter: " << i++; LOG(debug) << "debug message, counter: " << i++;
LOG(detail) << "detail message, counter: " << i++;
LOG(info) << "info message, counter: " << i++; LOG(info) << "info message, counter: " << i++;
LOG(state) << "state message, counter: " << i++; LOG(state) << "state message, counter: " << i++;
LOG(warn) << "warning message, counter: " << i++; LOG(warn) << "warning message, counter: " << i++;