/** ****************************************************************************** @file /common/Log.cpp @brief Logovaci trida @author Vta, Vajicek @version 0.1 ******************************************************************************/ // #include "common/Log.h" #include "common/types.h" #include "common/compatibility.h" #include "common/utils.h" #include "common/Interface.h" // #include #include #include #include #ifdef WIN32 #include #endif #ifdef WIN32 #include #endif #ifdef _K_EDITOR_ //#include #endif /////////////////////////////////////////////////////////////////////////////// #ifdef K8_LOG TLog Log(GLOBALLOG_STDOUT); #endif #ifdef K8_PROFILER TLog Profiler("profiler.log"); #endif /////////////////////////////////////////////////////////////////////////////// void CheckDirectory() { #ifdef WIN32 // posun z adresare bin, pokud nekdo pustil primo .exe char dir[K8_MAX_PATH_LEN]; _getcwd(dir, K8_MAX_PATH_LEN ); if (dir!=NULL) { int len = (int)strlen(dir); if (len>4){ if ((dir[len-1]=='n') && (dir[len-2]=='i') && (dir[len-3]=='b')) { #ifdef _K_EDITOR_ chdir(".."); #else _chdir(".."); #endif } } } #endif } /////////////////////////////////////////////////////////////////////////////// void TLog::AssertMsg(int b,char* m) { if(!b){ LogMsg(m); exit(-1); } } void TLog::LogMsg(char* format,...) { va_list args; va_start( args, format ); vsnprintf( buffer,MAXLOGBUFFER_LEN ,format, args ); // if(!sout){ FILE* f = fopen(file,"a+"); if( f ){ fprintf(f, buffer ); fclose(f); } } else{ printf( buffer ); } } void TLog::LogMsgId(int prior, const char * format,...) { va_list args; va_start( args, format ); if(prior > priority) { vsnprintf( buffer,MAXLOGBUFFER_LEN ,format, args ); if(!sout){ FILE* f = fopen(file,"a+"); if( f ){ fprintf(f, buffer); fprintf(f, "\n"); fclose(f); } } else{ printf( buffer ); printf( "\n"); } } } void TLog::LogArray(int c,int s,char* formatone,void* d){ // strcpy(buffer,""); for(int i=0;iMAXLOGBUFFER_LEN/2){ strcpy(buffer,""); printf( buffer ); } sprintf(buffer+l, formatone,((char*)d+s*i)); } // printf( buffer ); // } void TLog::RC(){ counter = 0; } void TLog::IC(){ counter ++; } void TLog::LC(){ LogMsg(">>>>Counter: %d", counter); } //konstruktor TLog::TLog(char* filename, int prior){ priority = prior; counter = 0; sout = 0; strcpy(file, LOG_DIR); strcat(file, filename); FILE* f = fopen(file,"w"); if(f)fclose(f); else sout = 1; } TLog::TLog(int so ,int prior){ int r = rand(); #ifdef _K_EDITOR_ sprintf(file, "../../" LOG_DIR "%08d.log", r); #else CheckDirectory(); sprintf(file, LOG_DIR "%08d.log", r); #endif if(!so) { FILE* f = fopen(file,"w"); #ifdef _K_EDITOR_ // zase se to vrati sprintf(file, LOG_DIR "%08d.log", r); #endif if(f)fclose(f); } priority = prior; counter = 0; sout = so; } /////////////////////////////////////////////////////////////////////////////// void CONSOLE(char* msg){ #ifdef WIN32 MessageBox(NULL, msg, "8Kingdoms " VERSION, 0); #else printf(msg); #endif } /*****************************************************************************/