added request at28068 (split log files)

fixed all native debug errors in core
This commit is contained in:
Borja Ferrer 2006-04-13 16:29:01 +00:00
parent ed1b2914be
commit a5df31570e
9 changed files with 87 additions and 54 deletions

View File

@ -59,7 +59,7 @@ static cell AMX_NATIVE_CALL set_xvar_num(AMX *amx, cell *params)
{
if (g_xvars.setValue(params[1], params[2]))
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Invalid xvar id");
return 0;
}
@ -1104,7 +1104,7 @@ static cell AMX_NATIVE_CALL amx_md5_file(AMX *amx, cell *params)
if (!fp)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Cant open file \"%s\"", file);
return 0;
}
@ -1311,8 +1311,7 @@ static cell AMX_NATIVE_CALL register_event(AMX *amx, cell *params) /* 2 param */
if ((pos = g_events.getEventId(sTemp)) == 0)
{
AMXXLOG_Log("[AMXX] Invalid event (name \"%s\") (plugin \"%s\")", sTemp, plugin->getName());
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Invalid event (name \"%s\") (plugin \"%s\")", sTemp, plugin->getName());
return 0;
}
@ -1611,9 +1610,7 @@ static cell AMX_NATIVE_CALL message_begin(AMX *amx, cell *params) /* 4 param */
if (params[2] < 1 || ((params[2] > 63) // maximal number of engine messages
&& !GET_USER_MSG_NAME(PLID, params[2], NULL)))
{
AMXXLOG_Log("[AMXX] Plugin called message_begin with an invalid message id (%d).", params[2]);
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Plugin called message_begin with an invalid message id (%d).", params[2]);
return 0;
}
@ -1628,7 +1625,7 @@ static cell AMX_NATIVE_CALL message_begin(AMX *amx, cell *params) /* 4 param */
case MSG_PVS_R: case MSG_PAS_R:
if (numparam < 3)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Invalid number of parameters passed");
return 0;
}
@ -1645,7 +1642,7 @@ static cell AMX_NATIVE_CALL message_begin(AMX *amx, cell *params) /* 4 param */
case MSG_ONE:
if (numparam < 4)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Invalid number of parameters passed");
return 0;
}
@ -1806,12 +1803,6 @@ static cell AMX_NATIVE_CALL get_time(AMX *amx, cell *params) /* 3 param */
time_t td = time(NULL);
tm* lt = localtime(&td);
if (lt == 0)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
return 0;
}
char szDate[512];
strftime(szDate, 511, sptemp, lt);
@ -1828,7 +1819,7 @@ static cell AMX_NATIVE_CALL format_time(AMX *amx, cell *params) /* 3 param */
if (lt == 0)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Couldn't get localtime");
return 0;
}
@ -1854,7 +1845,7 @@ static cell AMX_NATIVE_CALL parse_time(AMX *amx, cell *params) /* 3 param */
if (mytime == 0)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Couldn't get localtime");
return 0;
}
@ -1865,7 +1856,7 @@ static cell AMX_NATIVE_CALL parse_time(AMX *amx, cell *params) /* 3 param */
if (mytime == 0)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Couldn't get localtime");
return 0;
}
@ -2217,9 +2208,7 @@ static cell AMX_NATIVE_CALL set_task(AMX *amx, cell *params) /* 2 param */
if (iFunc == -1)
{
AMXXLOG_Log("[AMXX] Function is not present (function \"%s\") (plugin \"%s\")", stemp, plugin->getName());
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Function is not present (function \"%s\") (plugin \"%s\")", stemp, plugin->getName());
return 0;
}
@ -2385,7 +2374,7 @@ static cell AMX_NATIVE_CALL pause(AMX *amx, cell *params) /* 3 param */
if (flags & 2) // pause function
{
AMXXLOG_Log("[AMXX] This usage of the native pause() has been deprecated!");
LogError(amx, AMX_ERR_NATIVE, "This usage of the native pause() has been deprecated!");
return 1;
}
else if (flags & 4)
@ -2421,7 +2410,7 @@ static cell AMX_NATIVE_CALL unpause(AMX *amx, cell *params) /* 3 param */
if (flags & 2)
{
AMXXLOG_Log("[AMXX] This usage of the native pause() has been deprecated!");
LogError(amx, AMX_ERR_NATIVE, "This usage of the native pause() has been deprecated!");
return 1;
}
else if (flags & 4)
@ -2576,7 +2565,7 @@ static cell AMX_NATIVE_CALL precache_sound(AMX *amx, cell *params) /* 1 param */
{
if (g_dontprecache)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Precaching not allowed");
return 0;
}
@ -2592,7 +2581,7 @@ static cell AMX_NATIVE_CALL precache_model(AMX *amx, cell *params) /* 1 param */
{
if (g_dontprecache)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Precaching not allowed");
return 0;
}
@ -2844,7 +2833,7 @@ static cell AMX_NATIVE_CALL parse_loguser(AMX *amx, cell *params)
if (len < 6) // no user to parse!?
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "No user name specified");
return 0;
}
@ -2868,7 +2857,7 @@ static cell AMX_NATIVE_CALL parse_loguser(AMX *amx, cell *params)
/******** GET AUTHID **********/
if (len <= 0)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "No Authid found");
return 0;
}
@ -2891,7 +2880,7 @@ static cell AMX_NATIVE_CALL parse_loguser(AMX *amx, cell *params)
/******** GET USERID **********/
if (len <= 0)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "No Userid found");
return 0;
}
@ -3364,8 +3353,7 @@ static cell AMX_NATIVE_CALL callfunc_push_byval(AMX *amx, cell *params)
if (g_CallFunc_CurParam == CALLFUNC_MAXPARAMS)
{
AMXXLOG_Log("[AMXX] callfunc_push_xxx: maximal parameters num: %d", CALLFUNC_MAXPARAMS);
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Callfunc_push_xxx: maximal parameters num: %d", CALLFUNC_MAXPARAMS);
return 0;
}

View File

@ -72,6 +72,7 @@
#include "amxxlog.h"
#define AMXXLOG_Log g_log.Log
#define AMXXLOG_Error g_log.LogError
#define AMX_VERSION "1.71"
extern AMX_NATIVE_INFO core_Natives[];

View File

@ -48,6 +48,7 @@ CLog::CLog()
{
m_LogType = 0;
m_LogFile.clear();
m_FoundError = false;
}
CLog::~CLog()
@ -226,3 +227,44 @@ void CLog::Log(const char *fmt, ...)
ALERT(at_logged, "%s\n", msg_);
}
}
void CLog::LogError(const char *fmt, ...)
{
static char file[256];
if (m_FoundError)
return;
// get time
time_t td;
time(&td);
tm *curTime = localtime(&td);
char date[32];
strftime(date, 31, "%m/%d/%Y - %H:%M:%S", curTime);
// msg
static char msg[3072];
va_list arglst;
va_start(arglst, fmt);
vsnprintf(msg, 3071, fmt, arglst);
va_end(arglst);
FILE *pF = NULL;
build_pathname_r(file, sizeof(file)-1, "%s/error_%02d%02d%02d.log", g_log_dir.c_str(), curTime->tm_mon + 1, curTime->tm_mday, 100 - curTime->tm_year);
pF = fopen(file, "a+");
if (pF)
{
fprintf(pF, "L %s: %s\n", date, msg);
fclose(pF);
} else {
ALERT(at_logged, "[AMXX] Unexpected fatal logging error (couldn't open %s for a+). AMXX Error Logging disabled for this map.\n", file);
m_FoundError = true;
return;
}
// print on server console
print_srvconsole("L %s: %s\n", date, msg);
}

View File

@ -36,6 +36,7 @@ class CLog
private:
String m_LogFile;
int m_LogType;
bool m_FoundError;
void GetLastFile(int &outMonth, int &outDay, String &outFilename);
void UseFile(const String &fileName);
@ -47,6 +48,7 @@ public:
void CloseFile();
void MapChange();
void Log(const char *fmt, ...);
void LogError(const char *fmt, ...);
};
#endif // __AMXXLOG_H__

View File

@ -556,15 +556,15 @@ void Debugger::Clear()
void Debugger::DisplayTrace(const char *message)
{
if (message != NULL)
AMXXLOG_Log("%s", message);
AMXXLOG_Error("%s", message);
char buffer[512];
FormatError(buffer, sizeof(buffer)-1);
const char *filename = _GetFilename();
AMXXLOG_Log("[AMXX] Displaying debug trace (plugin \"%s\")", filename);
AMXXLOG_Log("[AMXX] %s", buffer);
AMXXLOG_Error("[AMXX] Displaying debug trace (plugin \"%s\")", filename);
AMXXLOG_Error("[AMXX] %s", buffer);
int count = 0;
long lLine;
@ -573,7 +573,7 @@ void Debugger::DisplayTrace(const char *message)
while (pTrace)
{
GetTraceInfo(pTrace, lLine, function, file);
AMXXLOG_Log(
AMXXLOG_Error(
"[AMXX] [%d] %s::%s (line %d)",
count,
file,
@ -633,7 +633,7 @@ void Debugger::GenericMessage(AMX *amx, int err)
Debugger::FmtGenericMsg(amx, err, buffer, sizeof(buffer)-1);
if (buffer[0] != '\0')
AMXXLOG_Log("[AMXX] %s", buffer);
AMXXLOG_Error("[AMXX] %s", buffer);
}
Debugger::~Debugger()
@ -762,7 +762,7 @@ int Handler::HandleNative(const char *native, int index, int trap)
}
if (!trap)
{
AMXXLOG_Log("[AMXX] Runtime failure %d occurred in native filter. Aborting plugin load.", err);
AMXXLOG_Error("[AMXX] Runtime failure %d occurred in native filter. Aborting plugin load.", err);
return 0;
}
//handle this manually.
@ -773,7 +773,7 @@ int Handler::HandleNative(const char *native, int index, int trap)
} else if (err != -1) {
LogError(m_pAmx, err, NULL);
}
AMXXLOG_Log("[AMXX] NOTE: Runtime failures in native filters are not good!");
AMXXLOG_Error("[AMXX] NOTE: Runtime failures in native filters are not good!");
retval = 0;
}
if (!trap)
@ -833,10 +833,10 @@ int Handler::HandleError(const char *msg)
pDebugger->DisplayTrace(msg);
} else {
if (GetLastMsg())
AMXXLOG_Log("%s", GetLastMsg());
AMXXLOG_Error("%s", GetLastMsg());
Debugger::GenericMessage(m_pAmx, err);
}
AMXXLOG_Log("[AMXX] NOTE: Runtime failures in an error filter are not good!");
AMXXLOG_Error("[AMXX] NOTE: Runtime failures in an error filter are not good!");
}
if (pDebugger)
@ -864,7 +864,7 @@ static cell AMX_NATIVE_CALL set_error_filter(AMX *amx, cell *params)
if (!pHandler)
{
Debugger::GenericMessage(amx, AMX_ERR_NOTFOUND);
AMXXLOG_Log("[AMXX] Plugin not initialized correctly.");
AMXXLOG_Error("[AMXX] Plugin not initialized correctly.");
return 0;
}
@ -872,7 +872,7 @@ static cell AMX_NATIVE_CALL set_error_filter(AMX *amx, cell *params)
if (err != AMX_ERR_NONE)
{
Debugger::GenericMessage(amx, AMX_ERR_NOTFOUND);
AMXXLOG_Log("[AMXX] Function not found: %s", function);
AMXXLOG_Error("[AMXX] Function not found: %s", function);
return 0;
}
@ -952,7 +952,7 @@ static cell AMX_NATIVE_CALL set_native_filter(AMX *amx, cell *params)
if (!pHandler)
{
Debugger::GenericMessage(amx, AMX_ERR_NOTFOUND);
AMXXLOG_Log("[AMXX] Plugin not initialized correctly.");
AMXXLOG_Error("[AMXX] Plugin not initialized correctly.");
return 0;
}
@ -971,7 +971,7 @@ static cell AMX_NATIVE_CALL set_native_filter(AMX *amx, cell *params)
if (err != AMX_ERR_NONE)
{
Debugger::GenericMessage(amx, AMX_ERR_NOTFOUND);
AMXXLOG_Log("[AMXX] Function not found: %s", function);
AMXXLOG_Error("[AMXX] Function not found: %s", function);
return 0;
}

View File

@ -139,7 +139,7 @@ static cell AMX_NATIVE_CALL read_file(AMX *amx, cell *params) /* 5 param */
if ((fp =fopen(build_pathname("%s", szFile), "r")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Couldn't read file \"%s\"", szFile);
return 0;
}
@ -183,7 +183,7 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
{
if ((pFile = fopen(sFile, "a")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Couldn't write file \"%s\"", sFile);
return 0;
}
@ -199,7 +199,7 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
{
if ((pFile = fopen(sFile, "w")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Couldn't write file \"%s\"", sFile);
return 0;
}
@ -219,7 +219,7 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
if ((pTemp = tmpfile()) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Couldn't create temp file");
return 0;
}
@ -249,7 +249,7 @@ static cell AMX_NATIVE_CALL write_file(AMX *amx, cell *params) /* 3 param */
// now rewrite because file can be now smaller...
if ((pFile = fopen(sFile, "w")) == NULL)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Couldn't write file \"%s\"", sFile);
return 0;
}

View File

@ -80,14 +80,14 @@ const char *translate(AMX *amx, cell amxaddr, const char *key)
const char *testlang = amx_mldebug->string;
if (!g_langMngr.LangExists(testlang))
{
AMXXLOG_Log("[AMXX] \"%s\" is an invalid debug language", testlang);
AMXXLOG_Error("[AMXX] \"%s\" is an invalid debug language", testlang);
validlang = false;
}
g_langMngr.GetDef(testlang, key, debug_status);
if (validlang && debug_status == ERR_BADKEY)
AMXXLOG_Log("[AMXX] Language key \"%s\" not found for language \"%s\", check \"%s\"", key, testlang, GetFileName(amx));
AMXXLOG_Error("[AMXX] Language key \"%s\" not found for language \"%s\", check \"%s\"", key, testlang, GetFileName(amx));
}
if (def == NULL)
@ -96,7 +96,7 @@ const char *translate(AMX *amx, cell amxaddr, const char *key)
{
if (status == ERR_BADLANG && (BadLang_Table.AltFindOrInsert(pLangName).last + 120.0f < gpGlobals->time))
{
AMXXLOG_Log("[AMXX] Language \"%s\" not found", pLangName);
AMXXLOG_Error("[AMXX] Language \"%s\" not found", pLangName);
BadLang_Table.AltFindOrInsert(pLangName).last = gpGlobals->time;
}
}

View File

@ -1474,10 +1474,10 @@ extern "C" void LogError(AMX *amx, int err, const char *fmt, ...)
if (!pDebugger)
{
if (fmt)
AMXXLOG_Log("%s", msg_buffer);
AMXXLOG_Error("%s", msg_buffer);
Debugger::GenericMessage(amx, err);
AMXXLOG_Log("[AMXX] To enable debug mode, add \"debug\" after the plugin name in plugins.ini (without quotes).");
AMXXLOG_Error("[AMXX] To enable debug mode, add \"debug\" after the plugin name in plugins.ini (without quotes).");
//destroy original error code so the original is not displayed again
} else {
pDebugger->SetTracedError(err);

View File

@ -832,7 +832,7 @@ static cell AMX_NATIVE_CALL format_args(AMX *amx, cell *params)
if (pos < 0)
{
amx_RaiseError(amx, AMX_ERR_NATIVE);
LogError(amx, AMX_ERR_NATIVE, "Pos has to be a positive number");
return 0;
}