2009-04-20 05:43:20 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
2009-05-06 02:28:09 +02:00
|
|
|
* File: log.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Logging API.
|
2009-04-20 05:43:20 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
2009-06-01 23:29:26 +02:00
|
|
|
/*
|
|
|
|
* Note: See log.h.inc for header types and defines.
|
2009-04-20 05:43:20 +02:00
|
|
|
*/
|
2009-06-01 23:29:26 +02:00
|
|
|
|
|
|
|
|
2009-04-20 05:43:20 +02:00
|
|
|
/**
|
2009-06-01 23:29:26 +02:00
|
|
|
* Gets a module type as a human readable string.
|
|
|
|
*
|
|
|
|
* @param buffer Destination string buffer.
|
|
|
|
* @param maxlen Size of destination buffer.
|
|
|
|
* @param module Module type to convert.
|
|
|
|
*
|
|
|
|
* @return Number of cells written.
|
2009-04-20 05:43:20 +02:00
|
|
|
*/
|
2009-06-01 23:29:26 +02:00
|
|
|
LogGetModuleNameString(String:buffer[], maxlen, LogModules:module)
|
|
|
|
{
|
|
|
|
switch (module)
|
|
|
|
{
|
2009-06-07 17:51:37 +02:00
|
|
|
case LogModule_Account:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Account");
|
|
|
|
}
|
2009-06-01 23:29:26 +02:00
|
|
|
case LogModule_Antistick:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Anti-Stick");
|
|
|
|
}
|
|
|
|
case LogModule_Config:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Config");
|
|
|
|
}
|
|
|
|
case LogModule_Cvars:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "CVARs");
|
|
|
|
}
|
|
|
|
case LogModule_Damage:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Damage");
|
|
|
|
}
|
|
|
|
case LogModule_Downloads:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Downloads");
|
|
|
|
}
|
|
|
|
case LogModule_Hitgroups:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Hit Groups");
|
|
|
|
}
|
|
|
|
case LogModule_Infect:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Infect");
|
|
|
|
}
|
|
|
|
case LogModule_Models:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Models");
|
|
|
|
}
|
|
|
|
case LogModule_Playerclasses:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Player Classes");
|
|
|
|
}
|
|
|
|
case LogModule_Soundeffects:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Sound Effects");
|
|
|
|
}
|
|
|
|
case LogModule_Tools:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Tools");
|
|
|
|
}
|
|
|
|
case LogModule_Volfetures:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Volumetric Features");
|
|
|
|
}
|
|
|
|
case LogModule_Weapons:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Weapons");
|
|
|
|
}
|
|
|
|
case LogModule_Weaponrestrict:
|
|
|
|
{
|
|
|
|
return strcopy(buffer, maxlen, "Weapon Restrictions");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Module mismatch.
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-20 05:43:20 +02:00
|
|
|
|
|
|
|
/**
|
2009-06-01 23:29:26 +02:00
|
|
|
* Check if the specified log flag is set.
|
2009-04-20 05:43:20 +02:00
|
|
|
*
|
2009-06-01 23:29:26 +02:00
|
|
|
* @param eventType The log flag to check.
|
|
|
|
* @return True if set, false otherwise.
|
2009-04-20 05:43:20 +02:00
|
|
|
*/
|
2009-06-01 23:29:26 +02:00
|
|
|
bool:LogCheckFlag(eventType)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
// Check if eventType is set.
|
|
|
|
if (GetConVarInt(g_hCvarsList[CVAR_LOG_FLAGS]) & eventType)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
return true;
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
2009-06-01 23:29:26 +02:00
|
|
|
else
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
return false;
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
2009-06-01 23:29:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the specified module is enabled in the log module filter cache.
|
|
|
|
*
|
|
|
|
* @param module Module to check.
|
|
|
|
* @return True if enabled, false otherwise.
|
|
|
|
*/
|
|
|
|
bool:LogCheckModuleFilter(LogModules:module)
|
|
|
|
{
|
|
|
|
if (LogModuleFilterCache[module])
|
2009-05-14 09:32:01 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
return true;
|
2009-05-14 09:32:01 +02:00
|
|
|
}
|
2009-06-01 23:29:26 +02:00
|
|
|
else
|
2009-05-14 09:32:01 +02:00
|
|
|
{
|
2009-06-01 23:29:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print a formatted message to logs depending on log settings.
|
|
|
|
*
|
|
|
|
* @param isConsole Optional. Specifies whether the log event came from
|
|
|
|
* client 0. Used in console commands, do not mix with
|
|
|
|
* regular log events. Default is false.
|
|
|
|
* @param logType Optional. Log type and action. Default is
|
|
|
|
* LogType_Normal.
|
|
|
|
* @param eventType Optional. A log flag describing What kind of log event
|
|
|
|
* it is. Default is LOG_CORE_EVENTS.
|
|
|
|
* @param module Module the log event were executed in.
|
|
|
|
* @param description Event type or function name. A short descriptive phrase
|
|
|
|
* to group together similar logs.
|
|
|
|
* @param text Log message. Can be formatted.
|
|
|
|
* @param ... Formatting parameters.
|
|
|
|
*/
|
|
|
|
LogEvent(bool:isConsole = false, LogTypes:logType = LogType_Normal, eventType = LOG_CORE_EVENTS, LogModules:module, const String:description[], const String:text[], any:...)
|
|
|
|
{
|
|
|
|
// Only do filter and flag checks if the log type isn't a fatal error.
|
|
|
|
if (logType != LogType_Fatal)
|
|
|
|
{
|
|
|
|
// Check if logging is disabled.
|
|
|
|
if (!GetConVarBool(g_hCvarsList[CVAR_LOG]))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if console is ignored.
|
|
|
|
if (isConsole && GetConVarBool(g_hCvarsList[CVAR_LOG_IGNORE_CONSOLE]))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check event type (log flag).
|
|
|
|
if (!LogCheckFlag(eventType))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if module filtering is enabled.
|
|
|
|
if (GetConVarBool(g_hCvarsList[CVAR_LOG_MODULE_FILTER]))
|
|
|
|
{
|
|
|
|
// Check if the specified module is enabled.
|
|
|
|
if (!LogCheckModuleFilter(module))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2009-05-14 09:32:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Format extra parameters into the log buffer.
|
|
|
|
decl String:logbuffer[LOG_MAX_LENGTH_FILE];
|
2009-06-05 05:58:48 +02:00
|
|
|
VFormat(logbuffer, sizeof(logbuffer), text, 7);
|
2009-05-14 09:32:01 +02:00
|
|
|
|
2009-06-01 23:29:26 +02:00
|
|
|
// Get human readable module name.
|
|
|
|
new String:modulename[64];
|
|
|
|
LogGetModuleNameString(modulename, sizeof(modulename), module);
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Format
|
2009-06-01 23:29:26 +02:00
|
|
|
Format(logbuffer, sizeof(logbuffer), "[%s] - [%s]: %s", modulename, description, logbuffer);
|
2009-04-27 04:00:38 +02:00
|
|
|
|
|
|
|
// Format other parameters onto the log text.
|
2009-06-01 23:29:26 +02:00
|
|
|
switch (logType)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Log type is normal.
|
2009-06-01 23:29:26 +02:00
|
|
|
case LogType_Normal:
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
LogMessage(logbuffer);
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
2009-04-27 04:00:38 +02:00
|
|
|
// Log type is error.
|
2009-06-01 23:29:26 +02:00
|
|
|
case LogType_Error:
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
LogError(logbuffer);
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
2009-05-14 09:32:01 +02:00
|
|
|
// Log type is fatal error.
|
2009-06-01 23:29:26 +02:00
|
|
|
case LogType_Fatal:
|
2009-04-29 01:58:41 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
SetFailState(logbuffer);
|
2009-04-29 01:58:41 +02:00
|
|
|
}
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
|
|
|
|
2009-06-01 23:29:26 +02:00
|
|
|
// Note: The phrase "Literal text" is a blank phrase to pass any string we want into it.
|
|
|
|
|
|
|
|
// Check if printing log events to admins is enabled.
|
|
|
|
if (GetConVarBool(g_hCvarsList[CVAR_LOG_PRINT_ADMINS]))
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
|
|
|
// Print text to admins.
|
2009-06-01 23:29:26 +02:00
|
|
|
TranslationPrintToChatAll(false, true, "Literal text", logbuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if printing log events to public chat is enabled.
|
|
|
|
if (GetConVarBool(g_hCvarsList[CVAR_LOG_PRINT_CHAT]))
|
|
|
|
{
|
|
|
|
TranslationPrintToChatAll(false, false, "Literal text", logbuffer);
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
|
|
|
}
|
2009-06-07 17:51:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates commands for logging module. Called when commands are created.
|
|
|
|
*/
|
|
|
|
LogOnCommandsCreate()
|
|
|
|
{
|
|
|
|
RegConsoleCmd("zr_log_list", Command_LogList, "List available logging flags and modules with their status values.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the zr_log_list command. Displays flags and module filter cache.
|
|
|
|
*
|
|
|
|
* @param client The client that executed the command.
|
|
|
|
* @param argc Number of arguments passed.
|
|
|
|
*/
|
|
|
|
public Action:Command_LogList(client, argc)
|
|
|
|
{
|
|
|
|
decl String:buffer[2048];
|
|
|
|
decl String:linebuffer[96];
|
|
|
|
decl String:module[64];
|
|
|
|
|
|
|
|
buffer[0] = 0;
|
|
|
|
|
|
|
|
// Set language.
|
|
|
|
SetGlobalTransTarget(client);
|
|
|
|
|
|
|
|
// Log flags:
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19t %-7t %t\n", "Log Generic Flag", "Log Value", "Log Status");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
StrCat(buffer, sizeof(buffer), "--------------------------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "LOG_CORE_EVENTS 1 %t\n", LogCheckFlag(LOG_CORE_EVENTS) ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "LOG_GAME_EVENTS 2 %t\n", LogCheckFlag(LOG_GAME_EVENTS) ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "LOG_PLAYER_COMMANDS 4 %t\n", LogCheckFlag(LOG_PLAYER_COMMANDS) ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "LOG_DEBUG 8 %t\n", LogCheckFlag(LOG_DEBUG) ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "LOG_DEBUG_DETAIL 16 %t\n\n", LogCheckFlag(LOG_DEBUG_DETAIL) ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
// Module filtering status:
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%t %t\n\n", "Log Module Filtering", GetConVarBool(g_hCvarsList[CVAR_LOG_MODULE_FILTER]) ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-23t %t\n", "Log Module", "Log Status");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
StrCat(buffer, sizeof(buffer), "--------------------------------------------------------------------------------\n");
|
|
|
|
|
|
|
|
// Module status:
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Account);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Account] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Antistick);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Antistick] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Config);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Config] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Cvars);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Cvars] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Damage);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Damage] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Downloads);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Downloads] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Hitgroups);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Hitgroups] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Infect);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Infect] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Models);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Models] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Playerclasses);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Playerclasses] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Soundeffects);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Soundeffects] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Tools);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Tools] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Volfetures);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Volfetures] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Weapons);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Weapons] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
LogGetModuleNameString(module, sizeof(module), LogModule_Weaponrestrict);
|
|
|
|
Format(linebuffer, sizeof(linebuffer), "%-19s %t\n", module, LogModuleFilterCache[LogModule_Weaponrestrict] ? "On" : "Off");
|
|
|
|
StrCat(buffer, sizeof(buffer), linebuffer);
|
|
|
|
|
|
|
|
ReplyToCommand(client, buffer);
|
|
|
|
|
|
|
|
return Plugin_Handled;
|
|
|
|
}
|