Added ability to automatically log debug info to a debug logfile (respecting the new read / write configurable path)
This commit is contained in:
parent
1e7cd63330
commit
ae10ab55b2
|
@ -402,6 +402,12 @@ when they are issued a command"/>
|
||||||
<enum value="false"/>
|
<enum value="false"/>
|
||||||
</enums>
|
</enums>
|
||||||
</field>
|
</field>
|
||||||
|
<field type="String">
|
||||||
|
<name value="Debug LogFile"/>
|
||||||
|
<variable-name value="DebugLogFile"/>
|
||||||
|
<description value="Debug LogFile to save debug output"/>
|
||||||
|
<default value=""/>
|
||||||
|
</field>
|
||||||
<field type="IntRange">
|
<field type="IntRange">
|
||||||
<name value="AI log"/>
|
<name value="AI log"/>
|
||||||
<variable-name value="AiLog"/>
|
<variable-name value="AiLog"/>
|
||||||
|
|
|
@ -167,6 +167,7 @@ int glestMain(int argc, char** argv){
|
||||||
Program *program= NULL;
|
Program *program= NULL;
|
||||||
ExceptionHandler exceptionHandler;
|
ExceptionHandler exceptionHandler;
|
||||||
exceptionHandler.install( getCrashDumpFileName() );
|
exceptionHandler.install( getCrashDumpFileName() );
|
||||||
|
string debugLogFile = "";
|
||||||
|
|
||||||
try{
|
try{
|
||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
|
@ -175,6 +176,11 @@ int glestMain(int argc, char** argv){
|
||||||
|
|
||||||
SystemFlags::enableNetworkDebugInfo = config.getBool("DebugNetwork","0");
|
SystemFlags::enableNetworkDebugInfo = config.getBool("DebugNetwork","0");
|
||||||
SystemFlags::enableDebugText = config.getBool("DebugMode","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);
|
NetworkInterface::setDisplayMessageFunction(ExceptionHandler::DisplayMessage);
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
|
|
||||||
static bool enableDebugText;
|
static bool enableDebugText;
|
||||||
static bool enableNetworkDebugInfo;
|
static bool enableNetworkDebugInfo;
|
||||||
|
static const char *debugLogFile;
|
||||||
|
|
||||||
static void OutputDebug(DebugType type, const char *fmt, ...);
|
static void OutputDebug(DebugType type, const char *fmt, ...);
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ namespace Shared{ namespace Util{
|
||||||
|
|
||||||
bool SystemFlags::enableDebugText = false;
|
bool SystemFlags::enableDebugText = false;
|
||||||
bool SystemFlags::enableNetworkDebugInfo = false;
|
bool SystemFlags::enableNetworkDebugInfo = false;
|
||||||
|
const char * SystemFlags::debugLogFile = NULL;
|
||||||
|
|
||||||
void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||||
if((type == debugSystem && SystemFlags::enableDebugText == false) ||
|
if((type == debugSystem && SystemFlags::enableDebugText == false) ||
|
||||||
|
@ -37,7 +39,27 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||||
va_list argList;
|
va_list argList;
|
||||||
va_start(argList, fmt);
|
va_start(argList, fmt);
|
||||||
|
|
||||||
|
// 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);
|
vprintf(fmt, argList);
|
||||||
|
}
|
||||||
|
|
||||||
va_end(argList);
|
va_end(argList);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user