summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJason Maskell <[email protected]>2016-05-31 13:54:29 +0200
committerJason Maskell <[email protected]>2016-05-31 13:54:29 +0200
commit9d4bad02e6eb15ec5cf62681923543776d66e9f1 (patch)
tree1f64f36d04a518a1369ce9e34ba30b0debea1b9f /common
parentAdded support for RFC 104, the logging interface: https://docs.google.com/doc... (diff)
downloadwaveworks_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 'common')
-rw-r--r--common/Logger.h25
-rw-r--r--common/LoggerImpl.cpp32
-rw-r--r--common/LoggerImpl.h56
3 files changed, 35 insertions, 78 deletions
diff --git a/common/Logger.h b/common/Logger.h
deleted file mode 100644
index 324b71e..0000000
--- a/common/Logger.h
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-namespace nv
-{
- enum struct LogSeverity
- {
- kInfo = 0, // Message contains information about normal and expected behavior
- kWarning = 1, // Message contains information about a potentially problematic situation
- kError = 2, // Message contains information about a problem
- kFatal = 3 // Message contains information about a fatal problem; program should be aborted
- };
-
- static const char * LogSeverityStrings[] = { "INFO", "WARNING", "ERROR", "FATAL" };
-
-
- // Note: Implementation of this interface must be thread-safe
- class ILogger
- {
- public:
- // �filename� is NULL and �linenumber� is 0 in release builds of GameWorks
- virtual void log(const char* text, LogSeverity severity, const char* filename, int linenumber) = 0;
- virtual void log(const wchar_t* text, LogSeverity severity, const wchar_t* filename, int linenumber) = 0;
- };
-}
-
diff --git a/common/LoggerImpl.cpp b/common/LoggerImpl.cpp
index 9a2921d..9fa81bd 100644
--- a/common/LoggerImpl.cpp
+++ b/common/LoggerImpl.cpp
@@ -3,10 +3,8 @@
#include <sstream>
#include <windows.h>
-LoggerWWSamples* g_Logger = nullptr;
-
LoggerWWSamples::LoggerWWSamples():
-LoggingLevel(nv::LogSeverity::kInfo)
+ LoggingLevel(nv::LogSeverity::kInfo)
{
}
@@ -27,20 +25,28 @@ void LoggerWWSamples::setLoggingLevel(nv::LogSeverity newLevel)
LoggingLevel = newLevel;
}
-void LoggerWWSamples::log(const char* text, nv::LogSeverity severity, const char* filename, int linenumber)
+void LoggerWWSamples::log(nv::LogSeverity severity, const wchar_t* filename, int linenumber, const wchar_t* format, ...)
{
- std::ostringstream out;
-
- out << filename << "(" << linenumber << "): " << "[" << nv::LogSeverityStrings[(int) severity] << "] " << text << std::endl;
+ if (getLoggingLevel() > severity)
+ return;
+
+ 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);
- OutputDebugStringA(out.str().c_str());
-}
-
-void LoggerWWSamples::log(const wchar_t* text, nv::LogSeverity severity, const wchar_t* filename, int linenumber)
-{
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/common/LoggerImpl.h b/common/LoggerImpl.h
index a07cead..35ac37a 100644
--- a/common/LoggerImpl.h
+++ b/common/LoggerImpl.h
@@ -1,5 +1,5 @@
#pragma once
-#include "Logger.h"
+#include "GFSDK_Logger.h"
#include <cstdarg>
#include <cstdio>
@@ -10,58 +10,34 @@ public:
LoggerWWSamples(nv::LogSeverity loggingLevel);
virtual ~LoggerWWSamples() = 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(const char* text, nv::LogSeverity severity, const char* filename, int linenumber) override;
+ virtual void log(nv::LogSeverity severity, const wchar_t* filename, int linenumber, const wchar_t* format, ...) override;
nv::LogSeverity getLoggingLevel();
void setLoggingLevel(nv::LogSeverity newLevel);
+ static LoggerWWSamples* GetInstance()
+ {
+ static LoggerWWSamples Instance;
+ return &Instance;
+ }
private:
nv::LogSeverity LoggingLevel;
};
-extern LoggerWWSamples* g_Logger;
-
-namespace wwsamples
-{
- inline void log(nv::LogSeverity severity, const char* filename, int linenumber, const char* format, ...)
- {
- if (g_Logger == nullptr)
- {
- g_Logger = new LoggerWWSamples();
- }
-
- if (g_Logger->getLoggingLevel() > severity)
- return;
-
- 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);
-
- g_Logger->log(buffer, severity, filename, linenumber);
- }
-}
-
+#ifndef NV_LOG
+// NOTE: This assumes we're using wide strings!
+#define WIDEWRAP2(s) L##s
+#define WIDEWRAP1(s) WIDEWRAP2(s)
-#ifndef NV_LOG
/// <param name="__VA_ARGS__">format, ...</param>
-#define NV_LOG(...) wwsamples::log(nv::LogSeverity::kInfo, __FILE__, __LINE__, __VA_ARGS__)
+#define NV_LOG(...) LoggerWWSamples::GetInstance()->log(nv::LogSeverity::kInfo, WIDEWRAP1(__FILE__), __LINE__, __VA_ARGS__)
/// <param name="__VA_ARGS__">format, ...</param>
-#define NV_WARN(...) wwsamples::log(nv::LogSeverity::kWarning, __FILE__, __LINE__, __VA_ARGS__)
+#define NV_WARN(...) LoggerWWSamples::GetInstance()->log(nv::LogSeverity::kWarning, WIDEWRAP1(__FILE__), __LINE__, __VA_ARGS__)
/// <param name="__VA_ARGS__">format, ...</param>
-#define NV_ERROR(...) wwsamples::log(nv::LogSeverity::kError, __FILE__, __LINE__, __VA_ARGS__)
+#define NV_ERROR(...) LoggerWWSamples::GetInstance()->log(nv::LogSeverity::kError, WIDEWRAP1(__FILE__), __LINE__, __VA_ARGS__)
/// <param name="__VA_ARGS__">format, ...</param>
-#define NV_FATAL(...) wwsamples::log(nv::LogSeverity::kFatal, __FILE__, __LINE__, __VA_ARGS__)
+#define NV_FATAL(...) LoggerWWSamples::GetInstance()->log(nv::LogSeverity::kFatal, WIDEWRAP1(__FILE__), __LINE__, __VA_ARGS__)
#endif \ No newline at end of file