bugfix for logfile sharing
This commit is contained in:
parent
76c256880e
commit
a750d4eda9
|
@ -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__);
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<SystemFlags::DebugType,SystemFlags::SystemFlagsType>::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";
|
||||
|
|
Loading…
Reference in New Issue
Block a user