logging functions moved from util.cpp to amxxlog.cpp; renamed to AMXXLOG_*; AMXXLOG_Init added (called from Meta_Attach)
UTIL_GetModulesNum moved to modules.cpp and renamed to countModules
This commit is contained in:
@ -270,96 +270,4 @@ void UTIL_FakeClientCommand(edict_t *pEdict, const char *cmd, const char *arg1,
|
||||
g_fakecmd.fake = true;
|
||||
MDLL_ClientCommand(pEdict);
|
||||
g_fakecmd.fake = false;
|
||||
}
|
||||
|
||||
String g_UTIL_LogFile;
|
||||
|
||||
void UTIL_MakeNewLogFile()
|
||||
{
|
||||
// build filename
|
||||
|
||||
time_t td;
|
||||
time(&td);
|
||||
tm *curTime = localtime(&td);
|
||||
|
||||
// create dir if not existing
|
||||
#ifdef __linux
|
||||
mkdir(build_pathname("%s", g_log_dir.str()), 0700);
|
||||
#else
|
||||
mkdir(build_pathname("%s", g_log_dir.str()));
|
||||
#endif
|
||||
|
||||
int i = 0;
|
||||
while (true)
|
||||
{
|
||||
g_UTIL_LogFile.set(build_pathname("%s/L%02d%02d%03d.log", g_log_dir.str(), curTime->tm_mon + 1, curTime->tm_mday, i));
|
||||
FILE *pTmpFile = fopen(g_UTIL_LogFile.str(), "r"); // open for reading to check whether the file exists
|
||||
if (!pTmpFile)
|
||||
break;
|
||||
fclose(pTmpFile);
|
||||
++i;
|
||||
}
|
||||
// Log logfile start
|
||||
UTIL_Log("AMX Mod X log file started (file \"%s/L%02d%02d%03d.log\") (version \"%s\")", g_log_dir.str(), curTime->tm_mon + 1, curTime->tm_mday, i, AMX_VERSION);
|
||||
}
|
||||
|
||||
void UTIL_Log(const char *fmt, ...)
|
||||
{
|
||||
// build message
|
||||
// :TODO: Overflow possible here
|
||||
char msg[3072];
|
||||
va_list arglst;
|
||||
va_start(arglst, fmt);
|
||||
vsprintf(msg, fmt, arglst);
|
||||
va_end(arglst);
|
||||
|
||||
// get time
|
||||
time_t td;
|
||||
time(&td);
|
||||
tm *curTime = localtime(&td);
|
||||
|
||||
char date[32];
|
||||
strftime(date, 31, "%m/%d/%Y - %H:%M:%S", curTime);
|
||||
|
||||
// log msg now
|
||||
FILE *pF = fopen(g_UTIL_LogFile.str(), "a+");
|
||||
if (!pF)
|
||||
return; // don't try to create a new logfile to prevent recursion crashes if there is an unforseen error
|
||||
|
||||
fprintf(pF, "L %s: %s\n", date, msg);
|
||||
fclose(pF);
|
||||
print_srvconsole("L %s: %s\n", date, msg);
|
||||
}
|
||||
|
||||
// Get the number of running modules
|
||||
int UTIL_GetModulesNum(int mode)
|
||||
{
|
||||
CList<CModule>::iterator iter;
|
||||
int num;
|
||||
switch (mode)
|
||||
{
|
||||
case UTIL_MODULES_ALL:
|
||||
return g_modules.size();
|
||||
case UTIL_MODULES_RUNNING:
|
||||
iter = g_modules.begin();
|
||||
num = 0;
|
||||
while (iter)
|
||||
{
|
||||
if ((*iter).getStatusValue() == MODULE_LOADED)
|
||||
++num;
|
||||
++iter;
|
||||
}
|
||||
return num;
|
||||
case UTIL_MODULES_STOPPED:
|
||||
iter = g_modules.begin();
|
||||
num = 0;
|
||||
while (iter)
|
||||
{
|
||||
if ((*iter).getStatusValue() != MODULE_LOADED)
|
||||
++num;
|
||||
++iter;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user