Raised This Month: $51 Target: $400
 12% 

logdebug.inc - Simple debug logging


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 02-26-2015 , 00:52   logdebug.inc - Simple debug logging
Reply With Quote #1

This is a simple include file which provides a LogDebug stock intended for use in debugging. Just #include it, call InitDebugLog, and use LogDebug wherever you desire. Requires SM 1.7 or later to compile and run.

PHP Code:
/**
 * Inits debug logging. You must call this in OnPluginStart().
 * 
 * @param convarName        A name to use for the cvar which controls debug log output. Also used as filename for logfile.
 * @param debugTag            Tag to prepend to messages, without []. Max 10 characters.
 * @param adminFlag            One or more admin flagbits which define whether a user is an "admin". If you pass multiple flags, users will need ALL flags.
 * @noreturn
 */
stock void InitDebugLog(const char[] convarName, const char[] debugTagint adminFlags ADMFLAG_GENERIC)

/**
 * Logs a message to all enabled debug output points
 * 
 * @param format        Message text with formatting tokens
 * @param ...            Variable number of format parameters
 * @return                true if message was output to at least one place
 */
stock bool LogDebug(const char[] formatany ...)

/**
 * Returns a bitstring containing bits enabled for each output location (see DEBUG_ constants)
 * 
 * @return                bitstring for enabled outputs
 */
stock int GetDebugOutputs() 
At runtime, you can add up the numbers associated with each output method and set the result in the cvar created with the name you specified.

PHP Code:
#define DEBUG_SERVER_CONSOLE        1     /**< Message will be routed to server console */
#define DEBUG_CLIENT_CONSOLE        2     /**< Message will be routed to all clients' consoles */
#define DEBUG_ADMIN_CONSOLE         4     /**< Message will be routed to consoles of admins with a flag specified by plugin */
#define DEBUG_CLIENT_CHAT           8     /**< Message will be routed to all clients' chat boxes (and consequently consoles) */
#define DEBUG_ADMIN_CHAT            16    /**< Message will be routed to chat boxes of admins with a flag specified by plugin */
#define DEBUG_LOG_FILE              32    /**< Message will be routed to plugin's debug log */ 
The cvar will be created with FCVAR_DONTRECORD so as to not clutter your AutoExecConfig.

If you define NO_DEBUG before #including the file, all functionality will be disabled. No cvar will be created and LogDebug will always return false.
Attached Files
File Type: inc logdebug.inc (4.9 KB, 353 views)
__________________

Last edited by Dr. McKay; 02-27-2015 at 14:11.
Dr. McKay is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode