From 39d233f5eb8506b83473f68987c77ac593dd6ef3 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 8 Jul 2014 17:26:50 +0200 Subject: [PATCH] SDL2: Pass SDL log into NeL log --HG-- branch : sdl2 --- code/nel/src/misc/debug.cpp | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/code/nel/src/misc/debug.cpp b/code/nel/src/misc/debug.cpp index c7667acc2..97d1733b0 100644 --- a/code/nel/src/misc/debug.cpp +++ b/code/nel/src/misc/debug.cpp @@ -32,6 +32,8 @@ #include "nel/misc/variable.h" #include "nel/misc/system_info.h" +#include + #ifdef NL_OS_WINDOWS # define _WIN32_WINDOWS 0x0410 # ifndef NL_COMP_MINGW @@ -1131,6 +1133,61 @@ std::string getLogDirectory() return LogPath; } +// Pass SDL log system into NeL log system +static void sdlLogOutputFunction(void *userdata, int category, SDL_LogPriority priority, const char *message) +{ + INelContext *context = (INelContext *)userdata; + CLog *log; + switch (priority) + { + case SDL_LOG_PRIORITY_VERBOSE: + case SDL_LOG_PRIORITY_DEBUG: + log = context->getDebugLog(); + break; + case SDL_LOG_PRIORITY_INFO: + log = context->getInfoLog(); + break; + case SDL_LOG_PRIORITY_WARN: + log = context->getWarningLog(); + break; + case SDL_LOG_PRIORITY_ERROR: + case SDL_LOG_PRIORITY_CRITICAL: + log = context->getErrorLog(); + break; + default: // Unreachable + log = context->getAssertLog(); + break; + } + switch (category) + { + case SDL_LOG_CATEGORY_APPLICATION: + log->setPosition(-1, "SDL_LOG_CATEGORY_APPLICATION"); + break; + case SDL_LOG_CATEGORY_ERROR: + log->setPosition(-1, "SDL_LOG_CATEGORY_ERROR"); + break; + case SDL_LOG_CATEGORY_SYSTEM: + log->setPosition(-1, "SDL_LOG_CATEGORY_SYSTEM"); + break; + case SDL_LOG_CATEGORY_AUDIO: + log->setPosition(-1, "SDL_LOG_CATEGORY_AUDIO"); + break; + case SDL_LOG_CATEGORY_VIDEO: + log->setPosition(-1, "SDL_LOG_CATEGORY_VIDEO"); + break; + case SDL_LOG_CATEGORY_RENDER: + log->setPosition(-1, "SDL_LOG_CATEGORY_RENDER"); + break; + case SDL_LOG_CATEGORY_INPUT: + log->setPosition(-1, "SDL_LOG_CATEGORY_INPUT"); + break; + default: + log->setPosition(-1, "SDL_LOG_CATEGORY_CUSTOM"); + break; + } + log->displayNL("%s", message); +} + // You should not call this, unless you know what you're trying to do (it kills debug/log)! // Destroys debug environment, to clear up the memleak log. // NeL context must be deleted immediately after debug destroyed, @@ -1229,6 +1286,8 @@ void createDebug (const char *logPath, bool logInFile, bool eraseLastLog) initDebug2(logInFile); + SDL_LogSetOutputFunction(sdlLogOutputFunction, &INelContext::getInstance()); + INelContext::getInstance().setAlreadyCreateSharedAmongThreads(true); // alreadyCreateSharedAmongThreads = true; }