diff --git a/mk/linux/configuration.xml b/mk/linux/configuration.xml index 25176759..5d4722d7 100644 --- a/mk/linux/configuration.xml +++ b/mk/linux/configuration.xml @@ -402,6 +402,12 @@ when they are issued a command"/> + + + + + + diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 17a1435d..1b1d4648 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -167,6 +167,7 @@ int glestMain(int argc, char** argv){ Program *program= NULL; ExceptionHandler exceptionHandler; exceptionHandler.install( getCrashDumpFileName() ); + string debugLogFile = ""; try{ Config &config = Config::getInstance(); @@ -175,6 +176,11 @@ int glestMain(int argc, char** argv){ SystemFlags::enableNetworkDebugInfo = config.getBool("DebugNetwork","0"); SystemFlags::enableDebugText = config.getBool("DebugMode","0"); + debugLogFile = config.getString("DebugLogFile",""); + if(getGameReadWritePath() != "") { + debugLogFile = getGameReadWritePath() + debugLogFile; + } + SystemFlags::debugLogFile = debugLogFile.c_str(); NetworkInterface::setDisplayMessageFunction(ExceptionHandler::DisplayMessage); diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index 341c7c16..17038a1f 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -29,6 +29,7 @@ public: static bool enableDebugText; static bool enableNetworkDebugInfo; + static const char *debugLogFile; static void OutputDebug(DebugType type, const char *fmt, ...); }; diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index e1b732b9..7ae5af8d 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include "leak_dumper.h" @@ -27,6 +28,7 @@ namespace Shared{ namespace Util{ bool SystemFlags::enableDebugText = false; bool SystemFlags::enableNetworkDebugInfo = false; +const char * SystemFlags::debugLogFile = NULL; void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { if((type == debugSystem && SystemFlags::enableDebugText == false) || @@ -37,7 +39,27 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { va_list argList; va_start(argList, fmt); - vprintf(fmt, argList); + // Either output to a logfile or + if(SystemFlags::debugLogFile != NULL && SystemFlags::debugLogFile[0] != 0) { + static ofstream fileStream; + if(fileStream.is_open() == false) { + printf("Opening logfile [%s]\n",SystemFlags::debugLogFile); + fileStream.open(SystemFlags::debugLogFile, ios_base::out | ios_base::trunc); + } + + //printf("Logfile is open [%s]\n",SystemFlags::debugLogFile); + + char szBuf[1024]=""; + vsprintf(szBuf,fmt, argList); + + //printf("writing to logfile [%s]\n",szBuf); + fileStream << szBuf; + fileStream.flush(); + } + // output to console + else { + vprintf(fmt, argList); + } va_end(argList); }