bugfix for logfile sharing
This commit is contained in:
parent
76c256880e
commit
a750d4eda9
|
@ -282,18 +282,18 @@ int glestMain(int argc, char** argv){
|
||||||
try{
|
try{
|
||||||
Config &config = Config::getInstance();
|
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::debugSystem).enabled = config.getBool("DebugMode","false");
|
||||||
SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled = config.getBool("DebugNetwork","false");
|
SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled = config.getBool("DebugNetwork","false");
|
||||||
SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled = config.getBool("DebugPerformance","false");
|
SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled = config.getBool("DebugPerformance","false");
|
||||||
SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled = config.getBool("DebugWorldSynch","false");
|
SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).enabled = config.getBool("DebugWorldSynch","false");
|
||||||
|
|
||||||
string debugWorldSynchLogFile = config.getString("DebugLogFileWorldSynch","");
|
|
||||||
string debugLogFile = config.getString("DebugLogFile","");
|
string debugLogFile = config.getString("DebugLogFile","");
|
||||||
if(getGameReadWritePath() != "") {
|
if(getGameReadWritePath() != "") {
|
||||||
debugLogFile = getGameReadWritePath() + debugLogFile;
|
debugLogFile = getGameReadWritePath() + debugLogFile;
|
||||||
}
|
}
|
||||||
|
string debugWorldSynchLogFile = config.getString("DebugLogFileWorldSynch","");
|
||||||
if(debugWorldSynchLogFile == "") {
|
if(debugWorldSynchLogFile == "") {
|
||||||
debugWorldSynchLogFile = debugLogFile;
|
debugWorldSynchLogFile = debugLogFile;
|
||||||
}
|
}
|
||||||
|
@ -303,6 +303,12 @@ int glestMain(int argc, char** argv){
|
||||||
SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).debugLogFileName = debugLogFile;
|
SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).debugLogFileName = debugLogFile;
|
||||||
SystemFlags::getSystemSettingType(SystemFlags::debugWorldSynch).debugLogFileName = debugWorldSynchLogFile;
|
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);
|
NetworkInterface::setDisplayMessageFunction(ExceptionHandler::DisplayMessage);
|
||||||
|
|
||||||
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__);
|
||||||
|
|
|
@ -42,12 +42,14 @@ public:
|
||||||
this->enabled = false;
|
this->enabled = false;
|
||||||
this->fileStream = NULL;
|
this->fileStream = NULL;
|
||||||
this->debugLogFileName = "";
|
this->debugLogFileName = "";
|
||||||
|
this->fileStreamOwner = false;
|
||||||
}
|
}
|
||||||
SystemFlagsType(DebugType debugType) {
|
SystemFlagsType(DebugType debugType) {
|
||||||
this->debugType = debugType;
|
this->debugType = debugType;
|
||||||
this->enabled = false;
|
this->enabled = false;
|
||||||
this->fileStream = NULL;
|
this->fileStream = NULL;
|
||||||
this->debugLogFileName = "";
|
this->debugLogFileName = "";
|
||||||
|
this->fileStreamOwner = false;
|
||||||
}
|
}
|
||||||
SystemFlagsType(DebugType debugType,bool enabled,
|
SystemFlagsType(DebugType debugType,bool enabled,
|
||||||
std::ofstream *fileStream,std::string debugLogFileName) {
|
std::ofstream *fileStream,std::string debugLogFileName) {
|
||||||
|
@ -55,11 +57,13 @@ public:
|
||||||
this->enabled = enabled;
|
this->enabled = enabled;
|
||||||
this->fileStream = fileStream;
|
this->fileStream = fileStream;
|
||||||
this->debugLogFileName = debugLogFileName;
|
this->debugLogFileName = debugLogFileName;
|
||||||
|
this->fileStreamOwner = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool enabled;
|
bool enabled;
|
||||||
std::ofstream *fileStream;
|
std::ofstream *fileStream;
|
||||||
std::string debugLogFileName;
|
std::string debugLogFileName;
|
||||||
|
bool fileStreamOwner;
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -79,8 +79,11 @@ void SystemFlags::Close() {
|
||||||
currentDebugLog.fileStream->is_open() == true) {
|
currentDebugLog.fileStream->is_open() == true) {
|
||||||
currentDebugLog.fileStream->close();
|
currentDebugLog.fileStream->close();
|
||||||
}
|
}
|
||||||
delete currentDebugLog.fileStream;
|
if(currentDebugLog.fileStreamOwner == true) {
|
||||||
|
delete currentDebugLog.fileStream;
|
||||||
|
}
|
||||||
currentDebugLog.fileStream = NULL;
|
currentDebugLog.fileStream = NULL;
|
||||||
|
currentDebugLog.fileStreamOwner = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SystemFlags::lockFile != -1) {
|
if(SystemFlags::lockFile != -1) {
|
||||||
|
@ -123,8 +126,7 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||||
currentDebugLog.fileStream->is_open() == false) {
|
currentDebugLog.fileStream->is_open() == false) {
|
||||||
|
|
||||||
// If the file is already open (shared) by another debug type
|
// If the file is already open (shared) by another debug type
|
||||||
// do not over-write the file but append
|
// do not over-write the file but share the stream pointer
|
||||||
bool appendToFileOnly = false;
|
|
||||||
for(std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType>::iterator iterMap = SystemFlags::debugLogFileList.begin();
|
for(std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType>::iterator iterMap = SystemFlags::debugLogFileList.begin();
|
||||||
iterMap != SystemFlags::debugLogFileList.end(); iterMap++) {
|
iterMap != SystemFlags::debugLogFileList.end(); iterMap++) {
|
||||||
SystemFlags::SystemFlagsType ¤tDebugLog2 = iterMap->second;
|
SystemFlags::SystemFlagsType ¤tDebugLog2 = iterMap->second;
|
||||||
|
@ -132,13 +134,14 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||||
if( iterMap->first != type &&
|
if( iterMap->first != type &&
|
||||||
currentDebugLog.debugLogFileName == currentDebugLog2.debugLogFileName &&
|
currentDebugLog.debugLogFileName == currentDebugLog2.debugLogFileName &&
|
||||||
currentDebugLog2.fileStream != NULL) {
|
currentDebugLog2.fileStream != NULL) {
|
||||||
appendToFileOnly = true;
|
currentDebugLog.fileStream = currentDebugLog2.fileStream;
|
||||||
|
currentDebugLog.fileStreamOwner = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string debugLog = currentDebugLog.debugLogFileName;
|
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) {
|
if(SystemFlags::lockFile == -1) {
|
||||||
const string lock_file_name = "debug.lck";
|
const string lock_file_name = "debug.lck";
|
||||||
|
@ -177,12 +180,8 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||||
|
|
||||||
if(currentDebugLog.fileStream == NULL) {
|
if(currentDebugLog.fileStream == NULL) {
|
||||||
currentDebugLog.fileStream = new std::ofstream();
|
currentDebugLog.fileStream = new std::ofstream();
|
||||||
}
|
|
||||||
if(appendToFileOnly == false) {
|
|
||||||
currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::trunc);
|
currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::trunc);
|
||||||
}
|
currentDebugLog.fileStreamOwner = true;
|
||||||
else {
|
|
||||||
currentDebugLog.fileStream->open(debugLog.c_str(), ios_base::out | ios_base::app);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
(*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n";
|
(*currentDebugLog.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user