mirror of https://github.com/AxioDL/logvisor.git
Added error count; exceptions now compile-time option
This commit is contained in:
parent
085920205b
commit
c61ff288b9
|
@ -5,6 +5,7 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
|
@ -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<std::unique_ptr<ILogger>> 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 <typename CharType>
|
||||
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 <typename CharType>
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ void RegisterThreadName(const char* name)
|
|||
}
|
||||
|
||||
std::vector<std::unique_ptr<ILogger>> 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()
|
||||
|
|
Loading…
Reference in New Issue