Skip to content

Commit

Permalink
Added error count; exceptions now compile-time option
Browse files Browse the repository at this point in the history
  • Loading branch information
jackoalan committed Jul 26, 2015
1 parent 0859202 commit c61ff28
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
38 changes: 36 additions & 2 deletions include/LogVisor/LogVisor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string.h>
#include <stdio.h>
#include <vector>
#include <atomic>
#include <memory>
#include <locale>
#include <codecvt>
Expand All @@ -16,6 +17,7 @@ namespace LogVisor
#define LOG_UCS2 1
#endif

#if LOG_VISOR_EXCEPTIONS
/**
* @brief Exception thrown when FatalError is issued
*/
Expand All @@ -42,6 +44,7 @@ class FatalException : public std::exception
inline const char* what() const noexcept {return m_what.c_str();}
#endif
};
#endif

/**
* @brief Severity level for log messages
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -146,11 +156,23 @@ class LogModule
{
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;
}

/**
Expand All @@ -165,11 +187,23 @@ class LogModule
{
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;
}
};

Expand Down
1 change: 1 addition & 0 deletions lib/LogVisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c61ff28

Please sign in to comment.