/*=========================================================================== * * File: DL_Log.H * Author: Dave Humphrey (uesp@m0use.net) * Created On: Monday, April 02, 2001 * * Defines the CLogFile class for handling output to a simple log file for * debugging purposes. * *=========================================================================*/ #ifndef __DL_LOG_H #define __DL_LOG_H /*=========================================================================== * * Begin Include Files * *=========================================================================*/ #include "dl_base.h" #include <stdarg.h> /*=========================================================================== * End of Include Files *=========================================================================*/ /*=========================================================================== * * Begin File Identification * *=========================================================================*/ #define DL_LOG_NAME "DL_Log.cpp" #define DL_LOG_VERSION "0.01d" #define DL_LOG_AUTHOR "Dave Humphrey (uesp@m0use.net)" #define DL_LOG_DATE "2 April 2001" /*=========================================================================== * End of File Identification *=========================================================================*/ /*=========================================================================== * * Begin Defines * *=========================================================================*/ /* Number of tab levels allowed in a log file */ #define LOGFILE_MAX_TABS 20 /*=========================================================================== * End of Defines *=========================================================================*/ /*=========================================================================== * * Begin Type and Structure Definitions * *=========================================================================*/ /* Logfile hook callback function type */ typedef void (*PLOGFILE_HOOKPROC) (const char* pString, va_list Args); typedef void (LOGFILE_HOOKPROC) (const char* pString, va_list Args); /* Parameters for the log file Open() method */ typedef enum { LOG_OPEN = 0, LOG_APPEND = 1 } logmode_t; /*=========================================================================== * End of Type and Structure Definitions *=========================================================================*/ /*=========================================================================== * * Class CLogFile Definition * * This class is used for handling log file operations used to output * various debugging information while the application is running. * *=========================================================================*/ class CLogFile { /*---------- Begin Private Class Members ----------------------*/ private: FILE* pLogFileHandle; /* The pointer to the log file steam */ int TabLevel; /* Number of tabs to pad output with */ PLOGFILE_HOOKPROC pHookProc; /* The optional hook function */ /*---------- Begin Protected Class Methods --------------------*/ protected: /* Outputs the current time to the log file */ boolean OutputCurrentTime (void); /* Outputs any tabs required by the current TabLevel */ boolean OutputTabs (void); /* Output a line to the log file */ boolean PrintLine (const char* pString, va_list Args); /*---------- Begin Public Class Methods -----------------------*/ public: /* Class Constructor and Destructor */ CLogFile (void); CLogFile (const char* pFilename, const logmode_t AppendFile = LOG_OPEN); virtual ~CLogFile (void) { Close(); } /* Closes the log file if it's currently open */ boolean Close (void); /* Access the file handle */ FILE* GetFileHandle (void) { return (pLogFileHandle); } /* Same as the Printf() method except it only works in debug builds. * For release builds the function is nothing (to save a call). */ #if defined(_DEBUG) void DebugPrintf (const char* pString, ...); #else void DebugPrintf (const char*, ...) { } #endif /* Increase or decrease the current tab level of log file */ void DecrementTabs (void); void IncrementTabs (void); /* Returns the open status of the log file */ boolean IsOpen (void) { return (boolean) ((pLogFileHandle == NULL) ? FALSE : TRUE); } /* Attempt to open a log file for output */ boolean Open (const char *pFilename, const logmode_t AppendFile = LOG_OPEN); /* Output the current date/time to the log file */ boolean OutputDate (void); /* Prints the current memory status to the log file */ void OutputMemoryStatus (void); /* Output a log entry */ boolean Printf (const char *pString, ...); /* Output a log entry to logfile and another stream */ boolean Printf (FILE* pFileHandle, const char* pString, ...); /* Change the hook procedure */ void SetHookProc (PLOGFILE_HOOKPROC pProc = NULL) { pHookProc = pProc; } /* Change the current tab level */ void SetTabLevel (const int NewTabLevel = 0); }; /*=========================================================================== * End of Class CLogFile Definition *=========================================================================*/ /*=========================================================================== * * Begin Test Function Prototypes * * Prototypes for functions to test module. Available only in DEBUG builds. * *=========================================================================*/ #if defined(_DEBUG) void Test_LogFile (void); #endif /*=========================================================================== * End of Test Function Prototypes *=========================================================================*/ /*=========================================================================== * * Begin External Variable Definitions * *=========================================================================*/ /* The primary log file */ extern CLogFile SystemLog; /*=========================================================================== * End of External Variable Definitions *=========================================================================*/ #endif /*=========================================================================== * End of File Dl_log.H *=========================================================================*/