Added ability to automatically log debug info to a debug logfile (respecting the new read / write configurable path)

This commit is contained in:
Mark Vejvoda
2010-03-23 06:57:41 +00:00
parent 1e7cd63330
commit ae10ab55b2
4 changed files with 36 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
#include <cstring>
#include <cstdio>
#include <stdarg.h>
#include <fstream>
#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);
}