mirror of
https://github.com/FairRootGroup/FairLogger.git
synced 2025-10-13 16:46:46 +00:00
Always define FAIR_MIN_SEVERITY
This commit is contained in:
parent
f3937bea6c
commit
84708ef8f2
|
@ -106,10 +106,10 @@ Logger will log the chosen severity and all above it (except "nolog", which deac
|
||||||
|
|
||||||
The minimum severity level can be configured at compile time via definition of `FAIR_MIN_SEVERITY`:
|
The minimum severity level can be configured at compile time via definition of `FAIR_MIN_SEVERITY`:
|
||||||
|
|
||||||
```C++
|
|
||||||
#define FAIR_MIN_SEVERITY warn // only allow severities >= warn
|
|
||||||
#include <fairlogger/Logger.h>
|
|
||||||
```
|
```
|
||||||
|
cmake -DFAIR_MIN_SEVERITY=warn ..
|
||||||
|
```
|
||||||
|
The above would only log severities equal to or above `warn`.
|
||||||
|
|
||||||
When `FAIR_MIN_SEVERITY` is not provided all severities are enabled.
|
When `FAIR_MIN_SEVERITY` is not provided all severities are enabled.
|
||||||
|
|
||||||
|
|
|
@ -26,13 +26,8 @@ using VSpec = VerbositySpec;
|
||||||
bool Logger::fColored = false;
|
bool Logger::fColored = false;
|
||||||
fstream Logger::fFileStream;
|
fstream Logger::fFileStream;
|
||||||
Verbosity Logger::fVerbosity = Verbosity::low;
|
Verbosity Logger::fVerbosity = Verbosity::low;
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
|
||||||
Severity Logger::fConsoleSeverity = Severity::FAIR_MIN_SEVERITY > Severity::info ? Severity::FAIR_MIN_SEVERITY : Severity::info;
|
Severity Logger::fConsoleSeverity = Severity::FAIR_MIN_SEVERITY > Severity::info ? Severity::FAIR_MIN_SEVERITY : Severity::info;
|
||||||
Severity Logger::fMinSeverity = Severity::FAIR_MIN_SEVERITY > Severity::info ? Severity::FAIR_MIN_SEVERITY : Severity::info;
|
Severity Logger::fMinSeverity = Severity::FAIR_MIN_SEVERITY > Severity::info ? Severity::FAIR_MIN_SEVERITY : Severity::info;
|
||||||
#else
|
|
||||||
Severity Logger::fConsoleSeverity = Severity::info;
|
|
||||||
Severity Logger::fMinSeverity = Severity::info;
|
|
||||||
#endif
|
|
||||||
Severity Logger::fFileSeverity = Severity::nolog;
|
Severity Logger::fFileSeverity = Severity::nolog;
|
||||||
function<void()> Logger::fFatalCallback;
|
function<void()> Logger::fFatalCallback;
|
||||||
unordered_map<string, pair<Severity, function<void(const string& content, const LogMetaData& metadata)>>> Logger::fCustomSinks;
|
unordered_map<string, pair<Severity, function<void(const string& content, const LogMetaData& metadata)>>> Logger::fCustomSinks;
|
||||||
|
@ -50,48 +45,48 @@ const string Logger::fProcessName = "?";
|
||||||
|
|
||||||
const unordered_map<string, Verbosity> Logger::fVerbosityMap =
|
const unordered_map<string, Verbosity> Logger::fVerbosityMap =
|
||||||
{
|
{
|
||||||
{ "veryhigh", Verbosity::veryhigh },
|
{ "veryhigh", Verbosity::veryhigh },
|
||||||
{ "high", Verbosity::high },
|
{ "high", Verbosity::high },
|
||||||
{ "medium", Verbosity::medium },
|
{ "medium", Verbosity::medium },
|
||||||
{ "low", Verbosity::low },
|
{ "low", Verbosity::low },
|
||||||
{ "verylow", Verbosity::verylow },
|
{ "verylow", Verbosity::verylow },
|
||||||
{ "VERYHIGH", Verbosity::veryhigh },
|
{ "VERYHIGH", Verbosity::veryhigh },
|
||||||
{ "HIGH", Verbosity::high },
|
{ "HIGH", Verbosity::high },
|
||||||
{ "MEDIUM", Verbosity::medium },
|
{ "MEDIUM", Verbosity::medium },
|
||||||
{ "LOW", Verbosity::low },
|
{ "LOW", Verbosity::low },
|
||||||
{ "VERYLOW", Verbosity::verylow },
|
{ "VERYLOW", Verbosity::verylow },
|
||||||
{ "user1", Verbosity::user1 },
|
{ "user1", Verbosity::user1 },
|
||||||
{ "user2", Verbosity::user2 },
|
{ "user2", Verbosity::user2 },
|
||||||
{ "user3", Verbosity::user3 },
|
{ "user3", Verbosity::user3 },
|
||||||
{ "user4", Verbosity::user4 }
|
{ "user4", Verbosity::user4 }
|
||||||
};
|
};
|
||||||
|
|
||||||
const unordered_map<string, Severity> Logger::fSeverityMap =
|
const unordered_map<string, Severity> Logger::fSeverityMap =
|
||||||
{
|
{
|
||||||
{ "nolog", Severity::nolog },
|
{ "nolog", Severity::nolog },
|
||||||
{ "NOLOG", Severity::nolog },
|
{ "NOLOG", Severity::nolog },
|
||||||
{ "error", Severity::error },
|
{ "error", Severity::error },
|
||||||
{ "ERROR", Severity::error },
|
{ "ERROR", Severity::error },
|
||||||
{ "warn", Severity::warn },
|
{ "warn", Severity::warn },
|
||||||
{ "WARN", Severity::warn },
|
{ "WARN", Severity::warn },
|
||||||
{ "warning", Severity::warn },
|
{ "warning", Severity::warn },
|
||||||
{ "WARNING", Severity::warn },
|
{ "WARNING", Severity::warn },
|
||||||
{ "state", Severity::state },
|
{ "state", Severity::state },
|
||||||
{ "STATE", Severity::state },
|
{ "STATE", Severity::state },
|
||||||
{ "info", Severity::info },
|
{ "info", Severity::info },
|
||||||
{ "INFO", Severity::info },
|
{ "INFO", Severity::info },
|
||||||
{ "debug", Severity::debug },
|
{ "debug", Severity::debug },
|
||||||
{ "DEBUG", Severity::debug },
|
{ "DEBUG", Severity::debug },
|
||||||
{ "debug1", Severity::debug1 },
|
{ "debug1", Severity::debug1 },
|
||||||
{ "DEBUG1", Severity::debug1 },
|
{ "DEBUG1", Severity::debug1 },
|
||||||
{ "debug2", Severity::debug2 },
|
{ "debug2", Severity::debug2 },
|
||||||
{ "DEBUG2", Severity::debug2 },
|
{ "DEBUG2", Severity::debug2 },
|
||||||
{ "debug3", Severity::debug3 },
|
{ "debug3", Severity::debug3 },
|
||||||
{ "DEBUG3", Severity::debug3 },
|
{ "DEBUG3", Severity::debug3 },
|
||||||
{ "debug4", Severity::debug4 },
|
{ "debug4", Severity::debug4 },
|
||||||
{ "DEBUG4", Severity::debug4 },
|
{ "DEBUG4", Severity::debug4 },
|
||||||
{ "trace", Severity::trace },
|
{ "trace", Severity::trace },
|
||||||
{ "TRACE", Severity::trace }
|
{ "TRACE", Severity::trace }
|
||||||
};
|
};
|
||||||
|
|
||||||
const array<string, 12> Logger::fSeverityNames =
|
const array<string, 12> Logger::fSeverityNames =
|
||||||
|
@ -301,12 +296,10 @@ string Logger::GetColoredSeverityString(Severity severity)
|
||||||
|
|
||||||
void Logger::SetConsoleSeverity(const Severity severity)
|
void Logger::SetConsoleSeverity(const Severity severity)
|
||||||
{
|
{
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
|
||||||
if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) {
|
if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) {
|
||||||
cout << "Requested severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << Severity::FAIR_MIN_SEVERITY << "), ignoring" << endl;
|
cout << "Requested severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << Severity::FAIR_MIN_SEVERITY << "), ignoring" << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
fConsoleSeverity = severity;
|
fConsoleSeverity = severity;
|
||||||
UpdateMinSeverity();
|
UpdateMinSeverity();
|
||||||
}
|
}
|
||||||
|
@ -328,12 +321,10 @@ Severity Logger::GetConsoleSeverity()
|
||||||
|
|
||||||
void Logger::SetFileSeverity(const Severity severity)
|
void Logger::SetFileSeverity(const Severity severity)
|
||||||
{
|
{
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
|
||||||
if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) {
|
if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) {
|
||||||
cout << "Requested severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << Severity::FAIR_MIN_SEVERITY << "), ignoring" << endl;
|
cout << "Requested severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << Severity::FAIR_MIN_SEVERITY << "), ignoring" << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
fFileSeverity = severity;
|
fFileSeverity = severity;
|
||||||
UpdateMinSeverity();
|
UpdateMinSeverity();
|
||||||
}
|
}
|
||||||
|
@ -351,12 +342,10 @@ void Logger::SetFileSeverity(const string& severityStr)
|
||||||
void Logger::SetCustomSeverity(const string& key, const Severity severity)
|
void Logger::SetCustomSeverity(const string& key, const Severity severity)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
|
||||||
if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) {
|
if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) {
|
||||||
cout << "Requested severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << Severity::FAIR_MIN_SEVERITY << "), ignoring" << endl;
|
cout << "Requested severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << Severity::FAIR_MIN_SEVERITY << "), ignoring" << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
fCustomSinks.at(key).first = severity;
|
fCustomSinks.at(key).first = severity;
|
||||||
UpdateMinSeverity();
|
UpdateMinSeverity();
|
||||||
} catch (const out_of_range& oor) {
|
} catch (const out_of_range& oor) {
|
||||||
|
@ -389,11 +378,7 @@ void Logger::CycleConsoleSeverityUp()
|
||||||
{
|
{
|
||||||
int current = static_cast<int>(fConsoleSeverity);
|
int current = static_cast<int>(fConsoleSeverity);
|
||||||
if (current == static_cast<int>(fSeverityNames.size()) - 1) {
|
if (current == static_cast<int>(fSeverityNames.size()) - 1) {
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
|
||||||
SetConsoleSeverity(Severity::FAIR_MIN_SEVERITY);
|
SetConsoleSeverity(Severity::FAIR_MIN_SEVERITY);
|
||||||
#else
|
|
||||||
SetConsoleSeverity(static_cast<Severity>(0));
|
|
||||||
#endif
|
|
||||||
} else {
|
} else {
|
||||||
SetConsoleSeverity(static_cast<Severity>(current + 1));
|
SetConsoleSeverity(static_cast<Severity>(current + 1));
|
||||||
}
|
}
|
||||||
|
@ -411,11 +396,7 @@ void Logger::CycleConsoleSeverityUp()
|
||||||
void Logger::CycleConsoleSeverityDown()
|
void Logger::CycleConsoleSeverityDown()
|
||||||
{
|
{
|
||||||
int current = static_cast<int>(fConsoleSeverity);
|
int current = static_cast<int>(fConsoleSeverity);
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
|
||||||
if (current == static_cast<int>(Severity::FAIR_MIN_SEVERITY)) {
|
if (current == static_cast<int>(Severity::FAIR_MIN_SEVERITY)) {
|
||||||
#else
|
|
||||||
if (current == 0) {
|
|
||||||
#endif
|
|
||||||
SetConsoleSeverity(static_cast<Severity>(fSeverityNames.size() - 1));
|
SetConsoleSeverity(static_cast<Severity>(fSeverityNames.size() - 1));
|
||||||
} else {
|
} else {
|
||||||
SetConsoleSeverity(static_cast<Severity>(current - 1));
|
SetConsoleSeverity(static_cast<Severity>(current - 1));
|
||||||
|
@ -560,16 +541,12 @@ string Logger::InitFileSink(const Severity severity, const string& filename, boo
|
||||||
fFileStream.open(fullName, fstream::out | fstream::app);
|
fFileStream.open(fullName, fstream::out | fstream::app);
|
||||||
|
|
||||||
if (fFileStream.is_open()) {
|
if (fFileStream.is_open()) {
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
|
||||||
if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) {
|
if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) {
|
||||||
cout << "Requested file sink severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << Severity::FAIR_MIN_SEVERITY << "), setting to " << Severity::FAIR_MIN_SEVERITY << endl;
|
cout << "Requested file sink severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << Severity::FAIR_MIN_SEVERITY << "), setting to " << Severity::FAIR_MIN_SEVERITY << endl;
|
||||||
fFileSeverity = Severity::FAIR_MIN_SEVERITY;
|
fFileSeverity = Severity::FAIR_MIN_SEVERITY;
|
||||||
} else {
|
} else {
|
||||||
fFileSeverity = severity;
|
fFileSeverity = severity;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
fFileSeverity = severity;
|
|
||||||
#endif
|
|
||||||
UpdateMinSeverity();
|
UpdateMinSeverity();
|
||||||
} else {
|
} else {
|
||||||
cout << "Error opening file: " << fullName;
|
cout << "Error opening file: " << fullName;
|
||||||
|
@ -628,16 +605,12 @@ void Logger::AddCustomSink(const string& key, Severity severity, function<void(c
|
||||||
{
|
{
|
||||||
lock_guard<mutex> lock(fMtx);
|
lock_guard<mutex> lock(fMtx);
|
||||||
if (fCustomSinks.count(key) == 0) {
|
if (fCustomSinks.count(key) == 0) {
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
|
||||||
if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) {
|
if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) {
|
||||||
cout << "Requested custom sink severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << Severity::FAIR_MIN_SEVERITY << "), setting to " << Severity::FAIR_MIN_SEVERITY << endl;
|
cout << "Requested custom sink severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << Severity::FAIR_MIN_SEVERITY << "), setting to " << Severity::FAIR_MIN_SEVERITY << endl;
|
||||||
fCustomSinks.insert(make_pair(key, make_pair(Severity::FAIR_MIN_SEVERITY, func)));
|
fCustomSinks.insert(make_pair(key, make_pair(Severity::FAIR_MIN_SEVERITY, func)));
|
||||||
} else {
|
} else {
|
||||||
fCustomSinks.insert(make_pair(key, make_pair(severity, func)));
|
fCustomSinks.insert(make_pair(key, make_pair(severity, func)));
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
fCustomSinks.insert(make_pair(key, make_pair(severity, func)));
|
|
||||||
#endif
|
|
||||||
UpdateMinSeverity();
|
UpdateMinSeverity();
|
||||||
} else {
|
} else {
|
||||||
cout << "Logger::AddCustomSink: sink '" << key << "' already exists, will not add again. Remove first with Logger::RemoveCustomSink(const string& key)" << endl;
|
cout << "Logger::AddCustomSink: sink '" << key << "' already exists, will not add again. Remove first with Logger::RemoveCustomSink(const string& key)" << endl;
|
||||||
|
|
|
@ -13,6 +13,10 @@
|
||||||
#warning "The symbol 'DEBUG' is used in FairRoot Logger. undefining..."
|
#warning "The symbol 'DEBUG' is used in FairRoot Logger. undefining..."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef FAIR_MIN_SEVERITY
|
||||||
|
#define FAIR_MIN_SEVERITY nolog
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef FAIRLOGGER_USE_BOOST_PRETTY_FUNCTION
|
#ifdef FAIRLOGGER_USE_BOOST_PRETTY_FUNCTION
|
||||||
#include <boost/current_function.hpp>
|
#include <boost/current_function.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
@ -322,13 +326,9 @@ class Logger
|
||||||
static bool fIsDestructed;
|
static bool fIsDestructed;
|
||||||
static struct DestructionHelper { ~DestructionHelper() { Logger::fIsDestructed = true; }} fDestructionHelper;
|
static struct DestructionHelper { ~DestructionHelper() { Logger::fIsDestructed = true; }} fDestructionHelper;
|
||||||
|
|
||||||
static bool constexpr SuppressSeverity(Severity sev __attribute__((unused)))
|
static bool constexpr SuppressSeverity(Severity sev)
|
||||||
{
|
{
|
||||||
#ifdef FAIR_MIN_SEVERITY
|
|
||||||
return sev < Severity::FAIR_MIN_SEVERITY;
|
return sev < Severity::FAIR_MIN_SEVERITY;
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -115,7 +115,6 @@ int main()
|
||||||
if (!Logger::Logging(Severity::error)) { cout << "Logger expected to log error, but it reports not to" << endl; return 1; }
|
if (!Logger::Logging(Severity::error)) { cout << "Logger expected to log error, but it reports not to" << endl; return 1; }
|
||||||
if (!Logger::Logging(Severity::fatal)) { cout << "Logger expected to log fatal, but it reports not to" << endl; return 1; }
|
if (!Logger::Logging(Severity::fatal)) { cout << "Logger expected to log fatal, but it reports not to" << endl; return 1; }
|
||||||
|
|
||||||
|
|
||||||
cout << "##### removing custom sink with error severity" << endl;
|
cout << "##### removing custom sink with error severity" << endl;
|
||||||
|
|
||||||
bool caught = false;
|
bool caught = false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user