diff options
| author | Jason Maskell <[email protected]> | 2016-05-31 13:54:29 +0200 |
|---|---|---|
| committer | Jason Maskell <[email protected]> | 2016-05-31 13:54:29 +0200 |
| commit | 9d4bad02e6eb15ec5cf62681923543776d66e9f1 (patch) | |
| tree | 1f64f36d04a518a1369ce9e34ba30b0debea1b9f /src | |
| parent | Added support for RFC 104, the logging interface: https://docs.google.com/doc... (diff) | |
| download | waveworks_archive-9d4bad02e6eb15ec5cf62681923543776d66e9f1.tar.xz waveworks_archive-9d4bad02e6eb15ec5cf62681923543776d66e9f1.zip | |
Renamed Logger.h to GFSDK_Logger.h since it's a shared header.
Removed the narrow char methods.
Removed the floating log functions.
Changed the ILogger::log() method to use varargs and printf() formatting.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Entrypoints.cpp | 1 | ||||
| -rw-r--r-- | src/InternalLogger.cpp | 26 | ||||
| -rw-r--r-- | src/InternalLogger.h | 74 |
3 files changed, 21 insertions, 80 deletions
diff --git a/src/Entrypoints.cpp b/src/Entrypoints.cpp index 953decf..2dd0c15 100644 --- a/src/Entrypoints.cpp +++ b/src/Entrypoints.cpp @@ -48,7 +48,6 @@ #include "orbis\GNM_Util.h" #endif #include "InternalLogger.h" -#include "Logger.h" // Misc helper macros which can be used to bracket entrypoints to: // - catch any and all exceptions, to keep them out of the app diff --git a/src/InternalLogger.cpp b/src/InternalLogger.cpp index e8e8898..de1f750 100644 --- a/src/InternalLogger.cpp +++ b/src/InternalLogger.cpp @@ -27,26 +27,28 @@ void InternalLogger::setLoggingLevel(nv::LogSeverity newLevel) LoggingLevel = newLevel; } -void InternalLogger::log(const char* text, nv::LogSeverity severity, const char* filename, int linenumber) +void InternalLogger::log(nv::LogSeverity severity, const wchar_t* filename, int linenumber, const wchar_t* format, ...) { if (getLoggingLevel() > severity) return; - std::ostringstream out; + wchar_t buffer[1024]; - out << filename << "(" << linenumber << "): " << "[" << nv::LogSeverityStrings[(int)severity] << "] " << text << std::endl; - - OutputDebugStringA(out.str().c_str()); -} - -void InternalLogger::log(const wchar_t* text, nv::LogSeverity severity, const wchar_t* filename, int linenumber) -{ - if (getLoggingLevel() > severity) - return; + va_list args; + va_start(args, format); +#if NV_GCC_FAMILY +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wformat-nonliteral" +#endif + _vsnwprintf_s(buffer, sizeof(buffer), format, args); +#if NV_GCC_FAMILY +#pragma GCC diagnostic pop +#endif + va_end(args); std::wstringstream out; - out << filename << "(" << linenumber << "): " << "[" << nv::LogSeverityStrings[(int)severity] << "] " << text << std::endl; + out << filename << "(" << linenumber << "): " << "[" << nv::LogSeverityStrings[(int)severity] << "] " << buffer << std::endl; OutputDebugStringW(out.str().c_str()); } diff --git a/src/InternalLogger.h b/src/InternalLogger.h index d10f263..334519c 100644 --- a/src/InternalLogger.h +++ b/src/InternalLogger.h @@ -1,6 +1,6 @@ #pragma once -#include "Logger.h" +#include "GFSDK_Logger.h" #include <cstdarg> #include <cstdio> #include <wtypes.h> @@ -15,8 +15,8 @@ public: InternalLogger(nv::LogSeverity loggingLevel); virtual ~InternalLogger() = default; - virtual void log(const char* text, nv::LogSeverity severity, const char* filename, int linenumber) override; - virtual void log(const wchar_t* text, nv::LogSeverity severity, const wchar_t* filename, int linenumber) override; +// virtual void log(nv::LogSeverity severity, const char* filename, int linenumber, const char* text, ...) override; + virtual void log(nv::LogSeverity severity, const wchar_t* filename, int linenumber, const wchar_t* text, ...) override; nv::LogSeverity getLoggingLevel(); void setLoggingLevel(nv::LogSeverity newLevel); @@ -34,75 +34,15 @@ private: extern nv::ILogger* g_UserLogger; -namespace WaveworksInternal -{ - inline void log(nv::LogSeverity severity, const wchar_t* filename, int linenumber, const wchar_t* format, ...) - { - wchar_t buffer[1024]; - - va_list args; - va_start(args, format); -#if NV_GCC_FAMILY -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif - _vsnwprintf_s(buffer, sizeof(buffer), format, args); -#if NV_GCC_FAMILY -#pragma GCC diagnostic pop -#endif - va_end(args); - - - // Only output to one logger at a time. May not be the desired behaviour. - if (g_UserLogger) - { - g_UserLogger->log(buffer, severity, filename, linenumber); - } - else - { - InternalLogger::GetInstance()->log(buffer, severity, filename, linenumber); - } - - } - - inline void log(nv::LogSeverity severity, const char* filename, int linenumber, const char* format, ...) - { - char buffer[1024]; - - va_list args; - va_start(args, format); -#if NV_GCC_FAMILY -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wformat-nonliteral" -#endif - vsnprintf_s(buffer, sizeof(buffer), format, args); -#if NV_GCC_FAMILY -#pragma GCC diagnostic pop -#endif - va_end(args); - - // Only output to one logger at a time. May not be the desired behaviour. - if (g_UserLogger) - { - g_UserLogger->log(buffer, severity, filename, linenumber); - } - else - { - InternalLogger::GetInstance()->log(buffer, severity, filename, linenumber); - } - } -} - - #ifndef NV_LOG /// <param name="__VA_ARGS__">format, ...</param> -#define NV_LOG(...) WaveworksInternal::log(nv::LogSeverity::kInfo, __DEF_FILE__, __LINE__, __VA_ARGS__) +#define NV_LOG(...) if (g_UserLogger) { g_UserLogger->log(nv::LogSeverity::kInfo, __DEF_FILE__, __LINE__, __VA_ARGS__); } else { InternalLogger::GetInstance()->log(nv::LogSeverity::kInfo, __DEF_FILE__, __LINE__, __VA_ARGS__); } /// <param name="__VA_ARGS__">format, ...</param> -#define NV_WARN(...) WaveworksInternal::log(nv::LogSeverity::kWarning, __DEF_FILE__, __LINE__, __VA_ARGS__) +#define NV_WARN(...) if (g_UserLogger) { g_UserLogger->log(nv::LogSeverity::kWarning, __DEF_FILE__, __LINE__, __VA_ARGS__); } else { InternalLogger::GetInstance()->log(nv::LogSeverity::kWarning, __DEF_FILE__, __LINE__, __VA_ARGS__); } /// <param name="__VA_ARGS__">format, ...</param> -#define NV_ERROR(...) WaveworksInternal::log(nv::LogSeverity::kError, __DEF_FILE__, __LINE__, __VA_ARGS__) +#define NV_ERROR(...) if (g_UserLogger) { g_UserLogger->log(nv::LogSeverity::kError, __DEF_FILE__, __LINE__, __VA_ARGS__); } else { InternalLogger::GetInstance()->log(nv::LogSeverity::kError, __DEF_FILE__, __LINE__, __VA_ARGS__); } /// <param name="__VA_ARGS__">format, ...</param> -#define NV_FATAL(...) WaveworksInternal::log(nv::LogSeverity::kFatal, __DEF_FILE__, __LINE__, __VA_ARGS__) +#define NV_FATAL(...) if (g_UserLogger) { g_UserLogger->log(nv::LogSeverity::kFatal, __DEF_FILE__, __LINE__, __VA_ARGS__); } else { InternalLogger::GetInstance()->log(nv::LogSeverity::kFatal, __DEF_FILE__, __LINE__, __VA_ARGS__); } #endif
\ No newline at end of file |