From a750d4eda90b9e8321a55378f5f810a0edf8241a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 28 Apr 2010 22:34:10 +0000 Subject: [PATCH] bugfix for logfile sharing --- source/glest_game/main/main.cpp | 10 ++++++++-- source/shared_lib/include/util/util.h | 4 ++++ source/shared_lib/sources/util/util.cpp | 19 +++++++++---------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 9d68313b..0993c661 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -282,18 +282,18 @@ int glestMain(int argc, char** argv){ try{ Config &config = Config::getInstance(); - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled = config.getBool("DebugMode","false"); SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled = config.getBool("DebugNetwork","false"); SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled = config.getBool("DebugPerformance","false"); SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled = config.getBool("DebugWorldSynch","false"); - string debugWorldSynchLogFile = config.getString("DebugLogFileWorldSynch",""); string debugLogFile = config.getString("DebugLogFile",""); if(getGameReadWritePath() != "") { debugLogFile = getGameReadWritePath() + debugLogFile; } + string debugWorldSynchLogFile = config.getString("DebugLogFileWorldSynch",""); if(debugWorldSynchLogFile == "") { debugWorldSynchLogFile = debugLogFile; } @@ -303,6 +303,12 @@ int glestMain(int argc, char** argv){ SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).debugLogFileName = debugLogFile; SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).debugLogFileName = debugWorldSynchLogFile; + printf("Startup settings are: debugSystem [%d], debugNetwork [%d], debugPerformance [%d], debugWorldSynch [%d]\n", + SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled, + SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled, + SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled, + SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled); + NetworkInterface::setDisplayMessageFunction(ExceptionHandler::DisplayMessage); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); diff --git a/source/shared_lib/include/util/util.h b/source/shared_lib/include/util/util.h index db31da26..55630264 100644 --- a/source/shared_lib/include/util/util.h +++ b/source/shared_lib/include/util/util.h @@ -42,12 +42,14 @@ public: this->enabled = false; this->fileStream = NULL; this->debugLogFileName = ""; + this->fileStreamOwner = false; } SystemFlagsType(DebugType debugType) { this->debugType = debugType; this->enabled = false; this->fileStream = NULL; this->debugLogFileName = ""; + this->fileStreamOwner = false; } SystemFlagsType(DebugType debugType,bool enabled, std::ofstream *fileStream,std::string debugLogFileName) { @@ -55,11 +57,13 @@ public: this->enabled = enabled; this->fileStream = fileStream; this->debugLogFileName = debugLogFileName; + this->fileStreamOwner = false; } bool enabled; std::ofstream *fileStream; std::string debugLogFileName; + bool fileStreamOwner; }; protected: diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index df3953f9..698c1016 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -79,8 +79,11 @@ void SystemFlags::Close() { currentDebugLog.fileStream->is_open() == true) { currentDebugLog.fileStream->close(); } - delete currentDebugLog.fileStream; + if(currentDebugLog.fileStreamOwner == true) { + delete currentDebugLog.fileStream; + } currentDebugLog.fileStream = NULL; + currentDebugLog.fileStreamOwner = false; } if(SystemFlags::lockFile != -1) { @@ -123,8 +126,7 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { currentDebugLog.fileStream->is_open() == false) { // If the file is already open (shared) by another debug type - // do not over-write the file but append - bool appendToFileOnly = false; + // do not over-write the file but share the stream pointer for(std::map::iterator iterMap = SystemFlags::debugLogFileList.begin(); iterMap != SystemFlags::debugLogFileList.end(); iterMap++) { SystemFlags::SystemFlagsType ¤tDebugLog2 = iterMap->second; @@ -132,13 +134,14 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { if( iterMap->first != type && currentDebugLog.debugLogFileName == currentDebugLog2.debugLogFileName && currentDebugLog2.fileStream != NULL) { - appendToFileOnly = true; + currentDebugLog.fileStream = currentDebugLog2.fileStream; + currentDebugLog.fileStreamOwner = false; break; } } string debugLog = currentDebugLog.debugLogFileName; - printf("Opening logfile [%s] type = %d, appendToFileOnly = %d\n",debugLog.c_str(),type, appendToFileOnly); + printf("Opening logfile [%s] type = %d, currentDebugLog.fileStreamOwner = %d\n",debugLog.c_str(),type, currentDebugLog.fileStreamOwner); if(SystemFlags::lockFile == -1) { const string lock_file_name = "debug.lck"; @@ -177,12 +180,8 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) { if(currentDebugLog.fileStream == NULL) { currentDebugLog.fileStream = new std::ofstream(); - } - if(appendToFileOnly == false) { currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::trunc); - } - else { - currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::app); + currentDebugLog.fileStreamOwner = true; } (*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n";