Add getters for file & custom sink severity

This commit is contained in:
Alexey Rybalchenko
2020-07-13 11:24:11 +02:00
parent de1014dabb
commit 1cb941021c
3 changed files with 41 additions and 6 deletions

View File

@@ -42,6 +42,10 @@ int main()
uniform_int_distribution<> distrib(1, 65536);
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$", [](){
LOG(state) << "state";
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$", [](){
LOG(state) << "state";
LOG(warn) << "warning";