mirror of
https://github.com/FairRootGroup/FairLogger.git
synced 2025-10-13 08:41:12 +00:00
Add getters for file & custom sink severity
This commit is contained in:
parent
de1014dabb
commit
1cb941021c
|
@ -350,6 +350,7 @@ 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 {
|
||||||
#ifdef FAIR_MIN_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 (" << fSeverityNames.at(static_cast<int>(Severity::FAIR_MIN_SEVERITY)) << "), ignoring" << endl;
|
cout << "Requested severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << fSeverityNames.at(static_cast<int>(Severity::FAIR_MIN_SEVERITY)) << "), ignoring" << endl;
|
||||||
|
@ -358,6 +359,10 @@ void Logger::SetCustomSeverity(const string& key, const Severity severity)
|
||||||
#endif
|
#endif
|
||||||
fCustomSinks.at(key).first = severity; // TODO: range checks
|
fCustomSinks.at(key).first = severity; // TODO: range checks
|
||||||
UpdateMinSeverity();
|
UpdateMinSeverity();
|
||||||
|
} catch (const out_of_range& oor) {
|
||||||
|
LOG(error) << "No custom sink with id '" << key << "' found";
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::SetCustomSeverity(const string& key, const string& severityStr)
|
void Logger::SetCustomSeverity(const string& key, const string& severityStr)
|
||||||
|
@ -370,6 +375,16 @@ void Logger::SetCustomSeverity(const string& key, const string& severityStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Severity Logger::GetCustomSeverity(const std::string& key)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return fCustomSinks.at(key).first;
|
||||||
|
} catch (const out_of_range& oor) {
|
||||||
|
LOG(error) << "No custom sink with id '" << key << "' found";
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Logger::CycleConsoleSeverityUp()
|
void Logger::CycleConsoleSeverityUp()
|
||||||
{
|
{
|
||||||
int current = static_cast<int>(fConsoleSeverity);
|
int current = static_cast<int>(fConsoleSeverity);
|
||||||
|
|
|
@ -244,9 +244,11 @@ class Logger
|
||||||
|
|
||||||
static void SetFileSeverity(const Severity severity);
|
static void SetFileSeverity(const Severity severity);
|
||||||
static void SetFileSeverity(const std::string& severityStr);
|
static void SetFileSeverity(const std::string& severityStr);
|
||||||
|
static Severity GetFileSeverity() { return fFileSeverity; }
|
||||||
|
|
||||||
static void SetCustomSeverity(const std::string& key, const Severity severity);
|
static void SetCustomSeverity(const std::string& key, const Severity severity);
|
||||||
static void SetCustomSeverity(const std::string& key, const std::string& severityStr);
|
static void SetCustomSeverity(const std::string& key, const std::string& severityStr);
|
||||||
|
static Severity GetCustomSeverity(const std::string& key);
|
||||||
|
|
||||||
static void CycleConsoleSeverityUp();
|
static void CycleConsoleSeverityUp();
|
||||||
static void CycleConsoleSeverityDown();
|
static void CycleConsoleSeverityDown();
|
||||||
|
|
|
@ -42,6 +42,10 @@ int main()
|
||||||
uniform_int_distribution<> distrib(1, 65536);
|
uniform_int_distribution<> distrib(1, 65536);
|
||||||
string name = Logger::InitFileSink(Severity::warn, string("test_log_" + to_string(distrib(gen))), true);
|
string name = Logger::InitFileSink(Severity::warn, string("test_log_" + to_string(distrib(gen))), true);
|
||||||
|
|
||||||
|
if (Logger::GetFileSeverity() != Severity::warn) {
|
||||||
|
throw runtime_error(ToStr("File sink severity (", Logger::fSeverityNames.at(static_cast<int>(Logger::GetFileSeverity())), ") does not match the expected one (", Logger::fSeverityNames.at(static_cast<int>(Severity::warn)), ")"));
|
||||||
|
}
|
||||||
|
|
||||||
CheckOutput("^\\[FATAL] fatal\n$", [](){
|
CheckOutput("^\\[FATAL] fatal\n$", [](){
|
||||||
LOG(state) << "state";
|
LOG(state) << "state";
|
||||||
LOG(warn) << "warning";
|
LOG(warn) << "warning";
|
||||||
|
@ -85,6 +89,20 @@ int main()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (Logger::GetCustomSeverity("CustomSink") != Severity::warn) {
|
||||||
|
throw runtime_error(ToStr("File sink severity (", Logger::fSeverityNames.at(static_cast<int>(Logger::GetCustomSeverity("CustomSink"))), ") does not match the expected one (", Logger::fSeverityNames.at(static_cast<int>(Severity::warn)), ")"));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool oorThrown = false;
|
||||||
|
try {
|
||||||
|
Logger::GetCustomSeverity("NonExistentSink");
|
||||||
|
} catch (const out_of_range& oor) {
|
||||||
|
oorThrown = true;
|
||||||
|
}
|
||||||
|
if (!oorThrown) {
|
||||||
|
throw runtime_error("Did not detect a severity request from a non-existent sink");
|
||||||
|
}
|
||||||
|
|
||||||
CheckOutput("^CustomSink warning\nCustomSink error\nCustomSink fatal\n\\[FATAL] fatal\n$", [](){
|
CheckOutput("^CustomSink warning\nCustomSink error\nCustomSink fatal\n\\[FATAL] fatal\n$", [](){
|
||||||
LOG(state) << "state";
|
LOG(state) << "state";
|
||||||
LOG(warn) << "warning";
|
LOG(warn) << "warning";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user