From c61ff288b90a6b4c833d01f62196eb0534bf2860 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 25 Jul 2015 16:41:37 -1000 Subject: [PATCH] Added error count; exceptions now compile-time option --- include/LogVisor/LogVisor.hpp | 38 +++++++++++++++++++++++++++++++++-- lib/LogVisor.cpp | 1 + 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/include/LogVisor/LogVisor.hpp b/include/LogVisor/LogVisor.hpp index dc812ce..1841362 100644 --- a/include/LogVisor/LogVisor.hpp +++ b/include/LogVisor/LogVisor.hpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -16,6 +17,7 @@ namespace LogVisor #define LOG_UCS2 1 #endif +#if LOG_VISOR_EXCEPTIONS /** * @brief Exception thrown when FatalError is issued */ @@ -42,6 +44,7 @@ public: inline const char* what() const noexcept {return m_what.c_str();} #endif }; +#endif /** * @brief Severity level for log messages @@ -85,6 +88,13 @@ void RegisterThreadName(const char* name); */ extern std::vector> MainLoggers; +/** + * @brief Centralized error counter + * + * All submodules accumulate this value + */ +extern std::atomic_size_t ErrorCount; + /** * @brief Centralized frame index * @@ -146,11 +156,23 @@ public: { va_list ap; va_start(ap, format); + report(severity, format, ap); + va_end(ap); + } + + template + inline void report(Level severity, const CharType* format, va_list ap) + { for (auto& logger : MainLoggers) logger->report(m_modName, severity, format, ap); if (severity == FatalError) +#if LOG_VISOR_EXCEPTIONS throw FatalException(format, ap); - va_end(ap); +#else + abort(); +#endif + else if (severity == Error) + ++ErrorCount; } /** @@ -165,11 +187,23 @@ public: { va_list ap; va_start(ap, format); + reportSource(severity, file, linenum, format, ap); + va_end(ap); + } + + template + inline void reportSource(Level severity, const char* file, unsigned linenum, const CharType* format, va_list ap) + { for (auto& logger : MainLoggers) logger->reportSource(m_modName, severity, file, linenum, format, ap); if (severity == FatalError) +#if LOG_VISOR_EXCEPTIONS throw FatalException(format, ap); - va_end(ap); +#else + abort(); +#endif + else if (severity == Error) + ++ErrorCount; } }; diff --git a/lib/LogVisor.cpp b/lib/LogVisor.cpp index 1c00bb3..9faf4d9 100644 --- a/lib/LogVisor.cpp +++ b/lib/LogVisor.cpp @@ -54,6 +54,7 @@ void RegisterThreadName(const char* name) } std::vector> MainLoggers; +std::atomic_size_t ErrorCount(0); static std::chrono::steady_clock MonoClock; static std::chrono::steady_clock::time_point GlobalStart = MonoClock.now(); static inline std::chrono::steady_clock::duration CurrentUptime()