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
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @section Log message max lengths.
|
|
|
|
*/
|
|
|
|
#define LOG_MAX_LENGTH_FILE 2048
|
|
|
|
#define LOG_MAX_LENGTH_CHAT 192
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @section Log format types
|
|
|
|
*/
|
2009-05-14 09:32:01 +02:00
|
|
|
#define LOG_FORMAT_TYPE_NORMAL 1 /** Printed in normal log. */
|
|
|
|
#define LOG_FORMAT_TYPE_DEBUG 2 /** Printed in normal log, flagged as debug. */
|
|
|
|
#define LOG_FORMAT_TYPE_ERROR 3 /** Printed in error log. */
|
|
|
|
#define LOG_FORMAT_TYPE_FATALERROR 4 /** Stops the plugin + LOG_FORMAT_TYPE_ERROR */
|
2009-04-20 05:43:20 +02:00
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-05-14 09:32:01 +02:00
|
|
|
* Print a formatted message to logs or error logs.
|
2009-04-20 05:43:20 +02:00
|
|
|
*
|
2009-05-14 09:32:01 +02:00
|
|
|
* @param type (Optional) Logging type. (See LOG_FORMAT_TYPE_* defines)
|
|
|
|
* @param module Module the log belongs to.
|
|
|
|
* @param description Short descriptive phrase to group together similar logs.
|
|
|
|
* @param text Text to print to log.
|
|
|
|
* @param ... Formatting parameters.
|
2009-04-20 05:43:20 +02:00
|
|
|
*/
|
2009-05-14 09:32:01 +02:00
|
|
|
LogPrintToLog(type = LOG_FORMAT_TYPE_NORMAL, const String:module[], const String:description[], const String:text[], any:...)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
|
|
|
// If logging is disabled, then stop.
|
2009-05-14 09:32:01 +02:00
|
|
|
new bool:log = GetConVarBool(g_hCvarsList[CVAR_LOG]);
|
2009-04-20 05:43:20 +02:00
|
|
|
if (!log)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// If module is filtered, then stop.
|
|
|
|
decl String:filtermodules[256];
|
|
|
|
GetConVarString(g_hCvarsList[CVAR_LOG_FILTER_MODULES], filtermodules, sizeof(filtermodules));
|
2009-04-27 04:00:38 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
if (StrContains(filtermodules, module, false) > -1)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// If description is filtered, then stop.
|
|
|
|
decl String:filterdescription[256];
|
|
|
|
GetConVarString(g_hCvarsList[CVAR_LOG_FILTER_DESCRIPTION], filterdescription, sizeof(filterdescription));
|
|
|
|
|
|
|
|
if (StrContains(filterdescription, description, false) > -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If debug is disabled, then stop.
|
|
|
|
new bool:filterdebug = GetConVarBool(g_hCvarsList[CVAR_LOG_FILTER_DEBUG]);
|
|
|
|
if (filterdebug && type == LOG_FORMAT_TYPE_DEBUG)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format extra parameters into the log buffer.
|
|
|
|
decl String:logbuffer[LOG_MAX_LENGTH_FILE];
|
|
|
|
VFormat(logbuffer, sizeof(logbuffer), text, 5);
|
|
|
|
|
|
|
|
// Format
|
|
|
|
Format(logbuffer, sizeof(logbuffer), "[%s]|[%s]: %s", module, description, logbuffer);
|
2009-04-27 04:00:38 +02:00
|
|
|
|
|
|
|
// Format other parameters onto the log text.
|
2009-04-20 05:43:20 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Log type is normal.
|
|
|
|
case LOG_FORMAT_TYPE_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-04-20 05:43:20 +02:00
|
|
|
case LOG_FORMAT_TYPE_ERROR:
|
|
|
|
{
|
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-04-29 01:58:41 +02:00
|
|
|
case LOG_FORMAT_TYPE_FATALERROR:
|
|
|
|
{
|
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-05-14 09:32:01 +02:00
|
|
|
// If print to admin cvar is enabled, then print to all connect admins.
|
|
|
|
new bool:printadmins = GetConVarBool(g_hCvarsList[CVAR_LOG_PRINT_ADMINS]);
|
|
|
|
if (printadmins)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
|
|
|
// Print text to admins.
|
2009-05-14 09:32:01 +02:00
|
|
|
// Note: The phrase "Literal text" is a blank phrase to pass any string we want into it.
|
2009-04-20 05:43:20 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
new bool:printchat = GetConVarBool(g_hCvarsList[CVAR_LOG_PRINT_CHAT]);
|
|
|
|
if (printchat)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToChatAll(false, true, "Literal text", logbuffer);
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
new bool:printconsole = GetConVarBool(g_hCvarsList[CVAR_LOG_PRINT_CONSOLE]);
|
|
|
|
if (printconsole)
|
2009-04-20 05:43:20 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
TranslationPrintToConsoleAll(false, true, "Literal text", logbuffer);
|
2009-04-20 05:43:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|