Пример #1
0
AiInterface::AiInterface(Game &game, int factionIndex, int teamIndex){
	this->world= game.getWorld();
	this->commander= game.getCommander();
	this->console= game.getConsole();

	this->factionIndex= factionIndex;
	this->teamIndex= teamIndex;
	timer= 0;

	//init ai
	ai.init(this);

	//config
	logLevel= Config::getInstance().getInt("AiLog");
	redir= Config::getInstance().getBool("AiRedir");

	//clear log file
	if(logLevel>0){
		FILE *f= fopen(getLogFilename().c_str(), "wt");
		if(f==NULL){
			throw runtime_error("Can't open file: "+getLogFilename());
		}
		fprintf(f, "%s", "Glest AI log file\n\n");
		fclose(f);
	}
}
Пример #2
0
FILE *openLog(const char *func, const char *file, int line) {
	char timestamp[TIMESTAMP_BUFFER_LEN];
#ifdef _WIN32
	char delimiter = '\\';
	SYSTEMTIME now;
	FILE *log;
	GetLocalTime(&now);
	sprintf_s(timestamp, TIMESTAMP_BUFFER_LEN, "%d-%02d-%02d %02d:%02d:%02d.%03d", now.wYear, now.wMonth, now.wDay, now.wHour, now.wMinute, now.wSecond, now.wMilliseconds);
#else
	char delimiter = '/';
	struct timeval tv;
	time_t curtime;
	gettimeofday(&tv, NULL);
	curtime = tv.tv_sec;
	strftime(timestamp, 30, "%Y-%m-%d %T", localtime(&curtime));
#ifdef __APPLE__
	sprintf(timestamp + strlen(timestamp), ".%03i ", tv.tv_usec / 1000);
#else
	sprintf(timestamp + strlen(timestamp), ".%03li ", tv.tv_usec / 1000);
#endif
#endif
#ifndef _WIN32
	FILE *log = fopen(getLogFilename(), "a");
#else
	log = _fsopen(getLogFilename(), "a", _SH_DENYNO);
#endif
	fprintf(log, "%s ", timestamp);
	if (file) {
		char *f = strrchr((char *)file, delimiter);
		if (!f) f = (char *)file;
		else f++;
		fprintf(log, "%s() [%s:%i] ", func, f, line);
	}
	return log;
}
Пример #3
0
void Settings::logInstructions(int argc, char **args) const {
        std::ofstream logFile;
        logFile.open(getLogFilename().c_str());
        if (!logFile)
                throw std::ios_base::failure("Can't write to " + getLogFilename());
        for (int i = 0; i < argc; i++)
                logFile << " " << args[i];
        logFile << std::endl;
        logFile.close();
}
Пример #4
0
void startTest() {
	TCHAR logFileName[1024];

	getLogFilename(logFileName);
	testLogFile = _tfopen(logFileName, _T("w"));
	if (!testLogFile)
		return;

	int pointTestErr = testPoint();
	logHLine();
	int vectorTestErr = testVector();
	logHLine();
	int lineTestErr = testLine();
	logHLine();
	int planeTestErr = testPlane();
	logHLine();
	int triangleTestErr = testTriangle();
	logHLine();
	int basisTestErr = testBasis();
	logHLine();
	int matrixTestErr = testMatrix();


	fclose(testLogFile);
	testLogFile = NULL;
}
Пример #5
0
void TestOsSysLogListener::endTest(CPPUNIT_NS::Test* test)
{
   // Flush and shutdown logging, so the log file is closed and able to be removed.
   OsSysLog::flush();
   OsSysLog::shutdown();


   // Remove the log file if it is an empty one.
   UtlString testLogFile = getLogFilename(test->getName().c_str());
   OsPath testLogFilePath(testLogFile);
   OsFileInfo tLogFInfo;
   OsStatus stat = OsFileSystem::getFileInfo(testLogFilePath, tLogFInfo);
   if (stat == OS_SUCCESS)
   {
      unsigned long logSz = 0;
      stat = tLogFInfo.getSize(logSz);
      if (stat == OS_SUCCESS && (logSz == 0))
      {
         stat = OsFileSystem::remove(testLogFile, FALSE, TRUE);
         if (stat != OS_SUCCESS)
         {
            printf("Failed to remove file %s\n", testLogFile.data());
         }
      }
   }
}
Пример #6
0
TestLogger::TestLogger(int thid) {
  char logFile[64];
  getLogFilename(logFile, sizeof(logFile), thid, ".txt");

  tid = thid;
  ouf.open(logFile, ios::out|ios::trunc);
  assert(ouf && "can't open log file for write!");
}
Пример #7
0
void AiInterface::printLog(int logLevel, const string &s){
    if(this->logLevel>=logLevel){
		string logString= "(" + intToStr(factionIndex) + ") " + s;

		//print log to file
		FILE *f= fopen(getLogFilename().c_str(), "at");
		if(f==NULL){
			throw runtime_error("Can't open file: "+getLogFilename());
		}
		fprintf(f, "%s\n", logString.c_str());
		fclose(f);
		
		//redirect to console
		if(redir) {
			console->addLine(logString);
		}
    }
}
Пример #8
0
void TestOsSysLogListener::startTest(CPPUNIT_NS::Test* test)
{
   UtlString testLogFile = getLogFilename(test->getName().c_str());

   OsSysLog::initialize(0,"UnitTest");
   OsSysLog::setLoggingPriority(PRI_DEBUG);

   OsFileSystem::remove(testLogFile, FALSE, TRUE);
   OsSysLog::setOutputFile(0,testLogFile);
}
Пример #9
0
BinLogger::BinLogger(int tid) {
  char logFile[64];
  getLogFilename(logFile, sizeof(logFile), tid, ".bin");

  foff = 0;
  fd = open(logFile, O_RDWR|O_CREAT, 0600);
  dprintf("logFile = %s\n", logFile);
  assert(fd >= 0 && "can't open log file!");
  assert(ftruncate(fd, LOG_SIZE) == 0);

  buf = NULL;
  mapLogTrunk();
}
Пример #10
0
void write_log(const char *func, const char *file, int line, const char *message, ...) {
	FILE *log;
	va_list args;

  if (access(getLogFilename(), W_OK) == -1) {
    return;
  }
    
	log = openLog(func, file, line);
	va_start(args, message);
	vfprintf(log, message, args);
	va_end(args);
	fprintf(log, "\n");
	fclose(log);
}
Пример #11
0
bool Log_File::init(const char *LogPath,
						 				const char *logFile,
						 				int				  perfilesize_M,
						 				int				  maxBackupFiles)
{
	time_t now_time;
	
	strncpy(m_Path,LogPath,512);
	
	//cout<<" perfilesize_M = "<<perfilesize_M<<endl;
	m_PerFilesize = perfilesize_M <1000 ? perfilesize_M:1000;
	m_PerFilesize = m_PerFilesize * 1024 *1024;
	
	//cout<<" m_PerFilesize = "<<m_PerFilesize<<endl;

	m_maxBackupFiles =maxBackupFiles <100?maxBackupFiles:100;
	
	if(strlen(m_Path)>0)
	{
		while(m_Path[strlen(m_Path) - 1]=='/')  
			m_Path[strlen(m_Path) - 1]='\0';
	}
	
	for(int i=0;i<2;i++)
	{
		if(!Pubc::isPathExist(m_Path))
		{
				char buf[1024];
				sprintf(buf,"mkdir -p %s",m_Path);
				system(buf);
		}
		if(!Pubc::isPathExist(m_Path))
			strcpy(m_Path,"./logs");
	}

	sprintf(baseName, "%s", logFile);
	sprintf(linkName, "%s/%s", m_Path, baseName);
	getLogFilename(baseName, &now_time);
	last_roll = (now_time + 8*3600)/ secondsOfDay * secondsOfDay;
	
	return Pubc::isPathExist(m_Path);	
}
Пример #12
0
inline void Log_File::checkLogFile()
{
	//cout<<"m_curSize= "<<m_curSize<<"  m_PerFilesize = " <<m_PerFilesize<<endl;
	time_t now, new_roll;
	now = time(NULL);
	new_roll = (now + 8*3600) / secondsOfDay * secondsOfDay;
	if(m_Fp_Log!=NULL&&m_curSize < m_PerFilesize && (new_roll == last_roll))
		 return;
	
	close();

	string logname =  getLogFilename(baseName, &now);
	sprintf(m_FileName, "%s/%s", m_Path, logname.c_str());
	last_roll = new_roll;
	
	//创建文件
	m_Fp_Log=fopen(m_FileName,"wt");

	unlink(linkName);
	symlink(logname.c_str(), linkName);
}
Пример #13
0
#pragma comment(lib, "advapi32")

#include "jvm_connection.hpp"
#include <Windows.h>
#include <winreg.h>
#include <jni.h>
#include "filesystem.h"
#include "timing.h"
#include "util.h"

static const char* LOG_FOLDER = getLogFolder();
static const char* LOG_FILENAME = getLogFilename();
int JAVA_VERSION = 0;

int findLastSeparator( const char* filename )
{
    for ( int i = strlen( filename ) - 1; i >= 0; i-- )
    {
        if ( filename[i] == '\\' )
            return ( i );
    }
    
    return ( -1 );
}

void renameOldLogFile()
{
    //_unlink( LOG_FILENAME );
    
    char* buffer = (char*)malloc( MAX_PATH );
    int folderLength = findLastSeparator( LOG_FILENAME );
Пример #14
0
std::string Trace::getDefaultLogFilename()
{
    return getLogFilename("vle.log");
}
Пример #15
0
/**
 * Creates an absolute path like <logDirectory>/<Date>_<Time>_'file'Err.txt
 * @param file is the suffix for the absolute path.
 * @return An absolute error log filename.
 */
std::string getErrLogFilename(const std::string& file)
{
    std::string errFile = file + "Err";
    return getLogFilename(errFile);
}