Added error count; exceptions now compile-time option

This commit is contained in:
Jack Andersen 2015-07-25 16:41:37 -10:00
parent 085920205b
commit c61ff288b9
2 changed files with 37 additions and 2 deletions

View File

@ -5,6 +5,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <vector> #include <vector>
#include <atomic>
#include <memory> #include <memory>
#include <locale> #include <locale>
#include <codecvt> #include <codecvt>
@ -16,6 +17,7 @@ namespace LogVisor
#define LOG_UCS2 1 #define LOG_UCS2 1
#endif #endif
#if LOG_VISOR_EXCEPTIONS
/** /**
* @brief Exception thrown when FatalError is issued * @brief Exception thrown when FatalError is issued
*/ */
@ -42,6 +44,7 @@ public:
inline const char* what() const noexcept {return m_what.c_str();} inline const char* what() const noexcept {return m_what.c_str();}
#endif #endif
}; };
#endif
/** /**
* @brief Severity level for log messages * @brief Severity level for log messages
@ -85,6 +88,13 @@ void RegisterThreadName(const char* name);
*/ */
extern std::vector<std::unique_ptr<ILogger>> MainLoggers; extern std::vector<std::unique_ptr<ILogger>> MainLoggers;
/**
* @brief Centralized error counter
*
* All submodules accumulate this value
*/
extern std::atomic_size_t ErrorCount;
/** /**
* @brief Centralized frame index * @brief Centralized frame index
* *
@ -146,11 +156,23 @@ public:
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
report(severity, format, ap);
va_end(ap);
}
template <typename CharType>
inline void report(Level severity, const CharType* format, va_list ap)
{
for (auto& logger : MainLoggers) for (auto& logger : MainLoggers)
logger->report(m_modName, severity, format, ap); logger->report(m_modName, severity, format, ap);
if (severity == FatalError) if (severity == FatalError)
#if LOG_VISOR_EXCEPTIONS
throw FatalException(format, ap); throw FatalException(format, ap);
va_end(ap); #else
abort();
#endif
else if (severity == Error)
++ErrorCount;
} }
/** /**
@ -165,11 +187,23 @@ public:
{ {
va_list ap; va_list ap;
va_start(ap, format); va_start(ap, format);
reportSource(severity, file, linenum, format, ap);
va_end(ap);
}
template <typename CharType>
inline void reportSource(Level severity, const char* file, unsigned linenum, const CharType* format, va_list ap)
{
for (auto& logger : MainLoggers) for (auto& logger : MainLoggers)
logger->reportSource(m_modName, severity, file, linenum, format, ap); logger->reportSource(m_modName, severity, file, linenum, format, ap);
if (severity == FatalError) if (severity == FatalError)
#if LOG_VISOR_EXCEPTIONS
throw FatalException(format, ap); throw FatalException(format, ap);
va_end(ap); #else
abort();
#endif
else if (severity == Error)
++ErrorCount;
} }
}; };

View File

@ -54,6 +54,7 @@ void RegisterThreadName(const char* name)
} }
std::vector<std::unique_ptr<ILogger>> MainLoggers; std::vector<std::unique_ptr<ILogger>> MainLoggers;
std::atomic_size_t ErrorCount(0);
static std::chrono::steady_clock MonoClock; static std::chrono::steady_clock MonoClock;
static std::chrono::steady_clock::time_point GlobalStart = MonoClock.now(); static std::chrono::steady_clock::time_point GlobalStart = MonoClock.now();
static inline std::chrono::steady_clock::duration CurrentUptime() static inline std::chrono::steady_clock::duration CurrentUptime()