diff --git a/logger/Logger.cxx b/logger/Logger.cxx index 5d0efc2..c14a4db 100644 --- a/logger/Logger.cxx +++ b/logger/Logger.cxx @@ -303,7 +303,7 @@ void Logger::SetConsoleSeverity(const Severity severity) { #ifdef FAIR_MIN_SEVERITY 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(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; } #endif @@ -330,7 +330,7 @@ void Logger::SetFileSeverity(const Severity severity) { #ifdef FAIR_MIN_SEVERITY 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(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; } #endif @@ -353,11 +353,11 @@ void Logger::SetCustomSeverity(const string& key, const Severity severity) try { #ifdef FAIR_MIN_SEVERITY 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(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; } #endif - fCustomSinks.at(key).first = severity; // TODO: range checks + fCustomSinks.at(key).first = severity; UpdateMinSeverity(); } catch (const out_of_range& oor) { LOG(error) << "No custom sink with id '" << key << "' found"; @@ -554,7 +554,7 @@ string Logger::InitFileSink(const Severity severity, const string& filename, boo if (fFileStream.is_open()) { #ifdef FAIR_MIN_SEVERITY if (severity < Severity::FAIR_MIN_SEVERITY && severity != Severity::nolog) { - cout << "Requested file sink severity is higher than the enabled compile-time FAIR_MIN_SEVERITY (" << fSeverityNames.at(static_cast(Severity::FAIR_MIN_SEVERITY)) << "), setting to " << fSeverityNames.at(static_cast(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; } else { fFileSeverity = severity; @@ -622,7 +622,7 @@ void Logger::AddCustomSink(const string& key, Severity severity, function(Severity::FAIR_MIN_SEVERITY)) << "), setting to " << fSeverityNames.at(static_cast(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))); } else { fCustomSinks.insert(make_pair(key, make_pair(severity, func))); diff --git a/logger/Logger.h b/logger/Logger.h index 8856c90..32b9aa9 100644 --- a/logger/Logger.h +++ b/logger/Logger.h @@ -363,6 +363,9 @@ class Logger static std::map fVerbosities; }; +inline std::ostream& operator<<(std::ostream& os, const Severity& s) { return os << Logger::SeverityName(s); } +inline std::ostream& operator<<(std::ostream& os, const Verbosity& v) { return os << Logger::VerbosityName(v); } + } // namespace fair #define IMP_CONVERTTOSTRING(s) # s diff --git a/test/Common.h b/test/Common.h index 629c7d6..7f836aa 100644 --- a/test/Common.h +++ b/test/Common.h @@ -5,6 +5,7 @@ * GNU Lesser General Public Licence (LGPL) version 3, * * copied verbatim in the file "LICENSE" * ********************************************************************************/ + #ifndef FAIR_LOGGER_TEST_COMMON_H #define FAIR_LOGGER_TEST_COMMON_H diff --git a/test/logger.cxx b/test/logger.cxx index f2ede5c..475c4d5 100644 --- a/test/logger.cxx +++ b/test/logger.cxx @@ -36,7 +36,7 @@ void printAllVerbositiesWithSeverity(Severity sev) Logger::SetConsoleSeverity(sev); for (uint32_t i = 0; i < Logger::fVerbosityNames.size(); ++i) { - cout << "##### testing severity '" << Logger::fSeverityNames.at(static_cast(sev)) << "' with verbosity '" << Logger::fVerbosityNames.at(i) << "'" << endl; + cout << "##### testing severity '" << sev << "' with verbosity '" << Logger::fVerbosityNames.at(i) << "'" << endl; Logger::SetVerbosity(static_cast(i)); printEverySeverity(); } diff --git a/test/severity.cxx b/test/severity.cxx index ae03545..03bb85c 100644 --- a/test/severity.cxx +++ b/test/severity.cxx @@ -7,7 +7,6 @@ ********************************************************************************/ #include "Common.h" - #include #include @@ -48,21 +47,21 @@ void CheckSeverity(Severity severity) if (sev == Severity::nolog) { if (i == 11) { if (!Logger::Logging(static_cast(i))) { - throw runtime_error(ToStr("expecting to be logging ", Logger::fSeverityNames.at(i), " during ", Logger::fSeverityNames.at(static_cast(sev)), ", but it is not.")); + throw runtime_error(ToStr("expecting to be logging ", Logger::fSeverityNames.at(i), " during ", sev, ", but it is not.")); } } else { if (Logger::Logging(static_cast(i))) { - throw runtime_error(ToStr("expecting to NOT be logging ", Logger::fSeverityNames.at(i), " during ", Logger::fSeverityNames.at(static_cast(sev)), ", but it is.")); + throw runtime_error(ToStr("expecting to NOT be logging ", Logger::fSeverityNames.at(i), " during ", sev, ", but it is.")); } } } else { if (i >= static_cast(sev)) { if (!Logger::Logging(static_cast(i))) { - throw runtime_error(ToStr("expecting to be logging ", Logger::fSeverityNames.at(i), " during ", Logger::fSeverityNames.at(static_cast(sev)), ", but it is not.")); + throw runtime_error(ToStr("expecting to be logging ", Logger::fSeverityNames.at(i), " during ", sev, ", but it is not.")); } } else { if (Logger::Logging(static_cast(i))) { - throw runtime_error(ToStr("expecting to NOT be logging ", Logger::fSeverityNames.at(i), " during ", Logger::fSeverityNames.at(static_cast(sev)), ", but it is.")); + throw runtime_error(ToStr("expecting to NOT be logging ", Logger::fSeverityNames.at(i), " during ", sev, ", but it is.")); } } } @@ -83,9 +82,9 @@ void CheckSeverity(Severity severity) int main() { - Logger::SetConsoleColor(true); - try { + Logger::SetConsoleColor(true); + cout << "##### testing " << Logger::fSeverityNames.size() << " severities..." << endl; for (uint32_t i = 0; i < Logger::fSeverityNames.size(); ++i) { CheckSeverity(static_cast(i)); diff --git a/test/sinks.cxx b/test/sinks.cxx index 2c76a5c..2a83e3d 100644 --- a/test/sinks.cxx +++ b/test/sinks.cxx @@ -20,18 +20,18 @@ using namespace fair::logger::test; int main() { - Logger::SetConsoleColor(false); - Logger::SetVerbosity(Verbosity::low); - - Logger::SetConsoleSeverity(Severity::nolog); +#ifdef FAIR_MIN_SEVERITY + if (static_cast(Severity::FAIR_MIN_SEVERITY) > static_cast(Severity::warn)) { + cout << "test requires at least FAIR_MIN_SEVERITY == warn to run, skipping" << endl; + return 0; + } +#endif try { -#ifdef FAIR_MIN_SEVERITY - if (static_cast(Severity::FAIR_MIN_SEVERITY) > static_cast(Severity::warn)) { - cout << "test requires at least FAIR_MIN_SEVERITY == warn to run, skipping" << endl; - return 0; - } -#endif + Logger::SetConsoleColor(false); + Logger::SetConsoleSeverity(Severity::nolog); + Logger::SetVerbosity(Verbosity::low); + if (Logger::Logging(Severity::warn)) { cout << "Logger expected to NOT log warn, but it reports to do so" << endl; return 1; } if (Logger::Logging(Severity::error)) { cout << "Logger expected to NOT log error, but it reports to do so" << endl; return 1; } if (!Logger::Logging(Severity::fatal)) { cout << "Logger expected to log fatal, but it reports not to" << endl; return 1; } @@ -43,7 +43,7 @@ int main() 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(Logger::GetFileSeverity())), ") does not match the expected one (", Logger::fSeverityNames.at(static_cast(Severity::warn)), ")")); + throw runtime_error(ToStr("File sink severity (", Logger::GetFileSeverity(), ") does not match the expected one (", Severity::warn, ")")); } CheckOutput("^\\[FATAL] fatal\n$", [](){ @@ -81,7 +81,7 @@ int main() cout << "CustomSink " << content << endl; if (metadata.severity != Severity::warn && metadata.severity != Severity::error && metadata.severity != Severity::fatal) { - throw runtime_error(ToStr("unexpected severity message arrived at custom sink that accepts only warn,error,fatal: ", Logger::fSeverityNames.at(static_cast(metadata.severity)))); + throw runtime_error(ToStr("unexpected severity message arrived at custom sink that accepts only warn,error,fatal: ", metadata.severity)); } if (metadata.severity_name != "WARN" && metadata.severity_name != "ERROR" && metadata.severity_name != "FATAL") { @@ -90,7 +90,7 @@ int main() }); if (Logger::GetCustomSeverity("CustomSink") != Severity::warn) { - throw runtime_error(ToStr("File sink severity (", Logger::fSeverityNames.at(static_cast(Logger::GetCustomSeverity("CustomSink"))), ") does not match the expected one (", Logger::fSeverityNames.at(static_cast(Severity::warn)), ")")); + throw runtime_error(ToStr("File sink severity (", Logger::GetCustomSeverity("CustomSink"), ") does not match the expected one (", Severity::warn, ")")); } bool oorThrown = false; diff --git a/test/verbosity.cxx b/test/verbosity.cxx index adc462d..ebdb8bc 100644 --- a/test/verbosity.cxx +++ b/test/verbosity.cxx @@ -7,7 +7,6 @@ ********************************************************************************/ #include "Common.h" - #include #include @@ -19,10 +18,10 @@ using namespace fair::logger::test; int main() { - Logger::SetConsoleColor(false); - Logger::SetConsoleSeverity(Severity::fatal); - try { + Logger::SetConsoleColor(false); + Logger::SetConsoleSeverity(Severity::fatal); + auto spec1 = VerbositySpec::Make(VerbositySpec::Info::file_line_function, VerbositySpec::Info::process_name); auto spec2 = VerbositySpec::Make(VerbositySpec::Info::process_name, VerbositySpec::Info::file_line_function);