mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 21:33:59 +02:00
Changed the logging system to be more flexible and to support world synch logging
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
|
||||
#include "streflop_cond.h"
|
||||
//#include <cmath>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace Shared{ namespace Graphics{
|
||||
|
||||
@@ -133,6 +135,12 @@ public:
|
||||
x/= m;
|
||||
y/= m;
|
||||
}
|
||||
|
||||
std::string getString() {
|
||||
std::ostringstream streamOut;
|
||||
streamOut << "x [" << x << "] y [" << y << "]";
|
||||
return streamOut.str();
|
||||
}
|
||||
};
|
||||
|
||||
typedef Vec2<int> Vec2i;
|
||||
@@ -298,6 +306,12 @@ public:
|
||||
return rv;
|
||||
}
|
||||
|
||||
std::string getString() {
|
||||
std::ostringstream streamOut;
|
||||
streamOut << "x [" << x << "] y [" << y << "] z [" << z << "]";
|
||||
return streamOut.str();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef Vec3<int> Vec3i;
|
||||
@@ -431,6 +445,13 @@ public:
|
||||
T dot(const Vec4<T> &v) const{
|
||||
return x*v.x + y*v.y + z*v.z + w*v.w;
|
||||
}
|
||||
|
||||
std::string getString() {
|
||||
std::ostringstream streamOut;
|
||||
streamOut << "x [" << x << "] y [" << y << "] z [" << z << "] w [" << w << "]";
|
||||
return streamOut.str();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
typedef Vec4<int> Vec4i;
|
||||
|
@@ -14,6 +14,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
using std::string;
|
||||
|
||||
@@ -21,28 +22,60 @@ namespace Shared{ namespace Util{
|
||||
|
||||
class SystemFlags
|
||||
{
|
||||
public:
|
||||
|
||||
enum DebugType {
|
||||
debugSystem,
|
||||
debugNetwork,
|
||||
debugPerformance,
|
||||
debugWorldSynch
|
||||
};
|
||||
|
||||
class SystemFlagsType
|
||||
{
|
||||
protected:
|
||||
DebugType debugType;
|
||||
|
||||
public:
|
||||
SystemFlagsType() {
|
||||
this->debugType = debugSystem;
|
||||
this->enabled = false;
|
||||
this->fileStream = NULL;
|
||||
this->debugLogFileName = "";
|
||||
}
|
||||
SystemFlagsType(DebugType debugType) {
|
||||
this->debugType = debugType;
|
||||
this->enabled = false;
|
||||
this->fileStream = NULL;
|
||||
this->debugLogFileName = "";
|
||||
}
|
||||
SystemFlagsType(DebugType debugType,bool enabled,
|
||||
std::ofstream *fileStream,std::string debugLogFileName) {
|
||||
this->debugType = debugType;
|
||||
this->enabled = enabled;
|
||||
this->fileStream = fileStream;
|
||||
this->debugLogFileName = debugLogFileName;
|
||||
}
|
||||
|
||||
bool enabled;
|
||||
std::ofstream *fileStream;
|
||||
std::string debugLogFileName;
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
static int lockFile;
|
||||
static string lockfilename;
|
||||
|
||||
static std::ofstream fileStream;
|
||||
static std::map<DebugType,SystemFlagsType> debugLogFileList;
|
||||
|
||||
public:
|
||||
|
||||
SystemFlags();
|
||||
~SystemFlags();
|
||||
|
||||
enum DebugType {
|
||||
debugSystem,
|
||||
debugNetwork,
|
||||
debugPerformance
|
||||
};
|
||||
|
||||
static bool enableDebugText;
|
||||
static bool enableNetworkDebugInfo;
|
||||
static bool enablePerformanceDebugInfo;
|
||||
static const char *debugLogFile;
|
||||
|
||||
static void init();
|
||||
static SystemFlagsType & getSystemSettingType(DebugType type) { return debugLogFileList[type]; }
|
||||
static void OutputDebug(DebugType type, const char *fmt, ...);
|
||||
static void Close();
|
||||
};
|
||||
|
@@ -35,12 +35,22 @@ using namespace Shared::Platform;
|
||||
|
||||
namespace Shared{ namespace Util{
|
||||
|
||||
bool SystemFlags::enableDebugText = false;
|
||||
bool SystemFlags::enableNetworkDebugInfo = false;
|
||||
bool SystemFlags::enablePerformanceDebugInfo = false;
|
||||
std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType> SystemFlags::debugLogFileList;
|
||||
|
||||
const char * SystemFlags::debugLogFile = NULL;
|
||||
ofstream SystemFlags::fileStream;
|
||||
void SystemFlags::init() {
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugSystem] = SystemFlags::SystemFlagsType(SystemFlags::debugSystem);
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugNetwork] = SystemFlags::SystemFlagsType(SystemFlags::debugNetwork);
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugPerformance] = SystemFlags::SystemFlagsType(SystemFlags::debugPerformance);
|
||||
SystemFlags::debugLogFileList[SystemFlags::debugWorldSynch] = SystemFlags::SystemFlagsType(SystemFlags::debugWorldSynch);
|
||||
}
|
||||
|
||||
//bool SystemFlags::enableDebugText = false;
|
||||
//bool SystemFlags::enableNetworkDebugInfo = false;
|
||||
//bool SystemFlags::enablePerformanceDebugInfo = false;
|
||||
//bool SystemFlags::enableWorldSynchDebugInfo = false;
|
||||
|
||||
//const char * SystemFlags::debugLogFile = NULL;
|
||||
//ofstream SystemFlags::fileStream;
|
||||
int SystemFlags::lockFile = -1;
|
||||
string SystemFlags::lockfilename = "";
|
||||
|
||||
@@ -69,9 +79,17 @@ SystemFlags::~SystemFlags() {
|
||||
void SystemFlags::Close() {
|
||||
printf("Closing logfile\n");
|
||||
|
||||
if(fileStream.is_open() == true) {
|
||||
SystemFlags::fileStream.close();
|
||||
for(std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType>::iterator iterMap = SystemFlags::debugLogFileList.begin();
|
||||
iterMap != SystemFlags::debugLogFileList.end(); iterMap++) {
|
||||
SystemFlags::SystemFlagsType ¤tDebugLog = iterMap->second;
|
||||
if( currentDebugLog.fileStream != NULL &&
|
||||
currentDebugLog.fileStream->is_open() == true) {
|
||||
currentDebugLog.fileStream->close();
|
||||
}
|
||||
delete currentDebugLog.fileStream;
|
||||
currentDebugLog.fileStream = NULL;
|
||||
}
|
||||
|
||||
if(SystemFlags::lockfilename != "") {
|
||||
#ifndef WIN32
|
||||
close(SystemFlags::lockFile);
|
||||
@@ -84,9 +102,8 @@ void SystemFlags::Close() {
|
||||
}
|
||||
|
||||
void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||
if((type == debugSystem && SystemFlags::enableDebugText == false) ||
|
||||
(type == debugNetwork && SystemFlags::enableNetworkDebugInfo == false ||
|
||||
type == debugPerformance && SystemFlags::enablePerformanceDebugInfo == false)) {
|
||||
SystemFlags::SystemFlagsType ¤tDebugLog = SystemFlags::debugLogFileList[type];
|
||||
if(currentDebugLog.enabled == false) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -104,10 +121,27 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||
vsprintf(szBuf,fmt, argList);
|
||||
|
||||
// Either output to a logfile or
|
||||
if(SystemFlags::debugLogFile != NULL && SystemFlags::debugLogFile[0] != 0) {
|
||||
if(fileStream.is_open() == false) {
|
||||
string debugLog = SystemFlags::debugLogFile;
|
||||
printf("Opening logfile [%s]\n",debugLog.c_str());
|
||||
if(currentDebugLog.debugLogFileName != "") {
|
||||
if( currentDebugLog.fileStream == NULL ||
|
||||
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;
|
||||
for(std::map<SystemFlags::DebugType,SystemFlags::SystemFlagsType>::iterator iterMap = SystemFlags::debugLogFileList.begin();
|
||||
iterMap != SystemFlags::debugLogFileList.end(); iterMap++) {
|
||||
SystemFlags::SystemFlagsType ¤tDebugLog2 = iterMap->second;
|
||||
|
||||
if( iterMap->first != type &&
|
||||
currentDebugLog.debugLogFileName == currentDebugLog2.debugLogFileName &&
|
||||
currentDebugLog2.fileStream != NULL) {
|
||||
appendToFileOnly = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
string debugLog = currentDebugLog.debugLogFileName;
|
||||
printf("Opening logfile [%s] type = %d, appendToFileOnly = %d\n",debugLog.c_str(),type, appendToFileOnly);
|
||||
|
||||
const string lock_file_name = "debug.lck";
|
||||
string lockfile = extractDirectoryPathFromFile(debugLog);
|
||||
@@ -142,14 +176,28 @@ void SystemFlags::OutputDebug(DebugType type, const char *fmt, ...) {
|
||||
printf("Opening additional logfile [%s]\n",debugLog.c_str());
|
||||
}
|
||||
|
||||
fileStream.open(debugLog.c_str(), ios_base::out | ios_base::trunc);
|
||||
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.fileStream) << "Starting Mega-Glest logging for type: " << type << "\n";
|
||||
(*currentDebugLog.fileStream).flush();
|
||||
}
|
||||
|
||||
//printf("Logfile is open [%s]\n",SystemFlags::debugLogFile);
|
||||
|
||||
//printf("writing to logfile [%s]\n",szBuf);
|
||||
fileStream << "[" << szBuf2 << "] " << szBuf;
|
||||
fileStream.flush();
|
||||
|
||||
assert(currentDebugLog.fileStream != NULL);
|
||||
|
||||
(*currentDebugLog.fileStream) << "[" << szBuf2 << "] " << szBuf;
|
||||
(*currentDebugLog.fileStream).flush();
|
||||
}
|
||||
// output to console
|
||||
else {
|
||||
|
Reference in New Issue
Block a user