/** * * *
* Log levels *
* *
* Functions *
* *
* Examples *
* * Debug messages * *

The following sets the log level (ideally in OnScriptInit()), and then prints a debug message. * * Log:level(LOGL_DEBUG);
* Log:debug("vehicles.inc", "Created %p's vehicle (%s) with vehicle SQL ID=%d", playerid, vehiclename, sqlid); *
*

* *
*//** */ #if defined _log_included #endinput #endif #define _log_included // Dependencies #include #include #include #include // Define the namespace #define Log: log_ // Definitions #define MAX_LOG_LENGTH 512 enum { LOGL_DEBUG = 1, LOGL_INFO, LOGL_WARNING, LOGL_ERROR, LOGL_NONE } static LOG_LEVEL = LOGL_DEBUG; // Forward declarations forward Log:level(level); forward Log:debug(prefix[], text[], va_args<>); forward Log:info(prefix[], text[], va_args<>); forward Log:warning(prefix[], text[], va_args<>); forward Log:error(prefix[], text[], va_args<>); public Log:level(level) { LOG_LEVEL = level; Log:info("log.inc", "The log level has been set to %d.", level); } /*------------------------------------------------------------*//** * * Prints a debug message in the console/log. This is later to * be changed to print to a new file, instead of server_log.txt * * *//*------------------------------------------------------------**/ public Log:debug(prefix[], text[], {Float,_}:...) { if(LOG_LEVEL != LOGL_DEBUG) { return; } new out[MAX_LOG_LENGTH] ; formatex(out, _, text, ___(2)); formatex(out, _, "DEBUG [%s]: %s", prefix, out); print(out); } /*------------------------------------------------------------*//** * Prints an informative message in the console/log. * *//*------------------------------------------------------------**/ public Log:info(prefix[], text[], {Float,_}:...) { if(LOG_LEVEL > LOGL_INFO) { return; } new out[MAX_LOG_LENGTH] ; formatex(out, _, text, ___(2)); formatex(out, _, "INFO [%s]: %s", prefix, out); print(out); } /*------------------------------------------------------------*//** * Prints a warning message in the console/log. * *//*------------------------------------------------------------**/ public Log:warning(prefix[], text[], {Float,_}:...) { if(LOG_LEVEL > LOGL_WARNING) { return; } new out[MAX_LOG_LENGTH] ; formatex(out, _, text, ___(2)); formatex(out, _, "WARNING [%s]: %s", prefix, out); print(out); PrintAmxBacktrace(); } /*------------------------------------------------------------*//** * * Prints an error message in the console/log. If DEVMODE is defined as 1, * this will shutdown the server * * *//*------------------------------------------------------------**/ public Log:error(prefix[], text[], {Float,_}:...) { if(LOG_LEVEL > LOGL_ERROR) { return; } new out[MAX_LOG_LENGTH] ; formatex(out, _, text, ___(2)); formatex(out, _, "ERROR [%s]: %s", prefix, out); print(out); PrintAmxBacktrace(); #if defined DEVMODE #if DEVMODE == 1 //Generate crash, credits to Southclaws new File:f = fopen("nonexistentfile", io_read), tmp[1]; fread(f, tmp); fclose(f); #endif #endif }