aboutsummaryrefslogtreecommitdiffstats
path: root/LibOVR/Src/Kernel/OVR_Log.cpp
diff options
context:
space:
mode:
authorBrad Davis <[email protected]>2014-07-24 16:47:31 -0700
committerBrad Davis <[email protected]>2014-07-24 16:47:31 -0700
commit0f49ce8fc6aa54224e4c0d6fda8c4527ad39cce1 (patch)
treeda07ebc6a7f75185bda857dd5f1c34710b416a93 /LibOVR/Src/Kernel/OVR_Log.cpp
parentca79271759ff7eecd22ec5c4db438370fe51d687 (diff)
0.4 Win-Beta0.4.0
Diffstat (limited to 'LibOVR/Src/Kernel/OVR_Log.cpp')
-rw-r--r--LibOVR/Src/Kernel/OVR_Log.cpp50
1 files changed, 42 insertions, 8 deletions
diff --git a/LibOVR/Src/Kernel/OVR_Log.cpp b/LibOVR/Src/Kernel/OVR_Log.cpp
index d5f8a68..c81845e 100644
--- a/LibOVR/Src/Kernel/OVR_Log.cpp
+++ b/LibOVR/Src/Kernel/OVR_Log.cpp
@@ -29,10 +29,13 @@ limitations under the License.
#include <stdarg.h>
#include <stdio.h>
-#if defined(OVR_OS_WIN32)
+#if defined(OVR_OS_WIN32)
+#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#elif defined(OVR_OS_ANDROID)
#include <android/log.h>
+#elif defined(OVR_OS_LINUX) || defined(OVR_OS_MAC)
+#include <syslog.h>
#endif
namespace OVR {
@@ -43,8 +46,24 @@ Log* volatile OVR_GlobalLog = 0;
//-----------------------------------------------------------------------------------
// ***** Log Implementation
+Log::Log(unsigned logMask) :
+ LoggingMask(logMask)
+{
+#ifdef OVR_OS_WIN32
+ hEventSource = RegisterEventSourceA(NULL, "OculusVR");
+ OVR_ASSERT(hEventSource != NULL);
+#endif
+}
+
Log::~Log()
{
+#ifdef OVR_OS_WIN32
+ if (hEventSource)
+ {
+ DeregisterEventSource(hEventSource);
+ }
+#endif
+
// Clear out global log
if (this == OVR_GlobalLog)
{
@@ -64,7 +83,7 @@ void Log::LogMessageVarg(LogMessageType messageType, const char* fmt, va_list ar
char buffer[MaxLogBufferMessageSize];
FormatLog(buffer, MaxLogBufferMessageSize, messageType, fmt, argList);
- DefaultLogOutput(buffer, IsDebugMessage(messageType));
+ DefaultLogOutput(buffer, messageType);
}
void OVR::Log::LogMessage(LogMessageType messageType, const char* pfmt, ...)
@@ -94,7 +113,7 @@ void Log::FormatLog(char* buffer, unsigned bufferSize, LogMessageType messageTyp
break;
}
- UPInt prefixLength = OVR_strlen(buffer);
+ size_t prefixLength = OVR_strlen(buffer);
char *buffer2 = buffer + prefixLength;
OVR_vsprintf(buffer2, bufferSize - prefixLength, fmt, argList);
@@ -103,8 +122,9 @@ void Log::FormatLog(char* buffer, unsigned bufferSize, LogMessageType messageTyp
}
-void Log::DefaultLogOutput(const char* formattedText, bool debug)
+void Log::DefaultLogOutput(const char* formattedText, LogMessageType messageType)
{
+ bool debug = IsDebugMessage(messageType);
#if defined(OVR_OS_WIN32)
// Under Win32, output regular messages to console if it exists; debug window otherwise.
@@ -116,10 +136,8 @@ void Log::DefaultLogOutput(const char* formattedText, bool debug)
{
::OutputDebugStringA(formattedText);
}
- else
- {
- fputs(formattedText, stdout);
- }
+
+ fputs(formattedText, stdout);
#elif defined(OVR_OS_ANDROID)
__android_log_write(ANDROID_LOG_INFO, "OVR", formattedText);
@@ -129,6 +147,22 @@ void Log::DefaultLogOutput(const char* formattedText, bool debug)
#endif
+ if (messageType == Log_Error)
+ {
+#if defined(OVR_OS_WIN32)
+ if (!ReportEventA(hEventSource, EVENTLOG_ERROR_TYPE, 0, 0, NULL, 1, 0, &formattedText, NULL))
+ {
+ OVR_ASSERT(false);
+ }
+#elif defined(OVR_OS_ANDROID)
+ // TBD
+#elif defined(OVR_OS_MAC) || defined(OVR_OS_LINUX)
+ syslog(LOG_ERR, "%s", formattedText);
+#else
+ // TBD
+#endif
+ }
+
// Just in case.
OVR_UNUSED2(formattedText, debug);
}