#pragma once #include #include #include #include #include #include #include "GWLPLogMacros.h" /* Logging class. Logs to RTF file and screen with one call. By: Theora */ //To use custom macros for this class, please specify them here #define DEBUG_TEXT OPT_DEBUG_LEVEL | OPT_NEWLINE | OPT_HEAD_DEBUG | OPT_APP_TIME #define WARNING_TEXT OPT_WARNING_LEVEL | OPT_C3 | OPT_HEAD_WARNING | OPT_APP_TIME | OPT_APP_LOCATION | OPT_CCSEMICOLON | OPT_NEWLINE #define NOTICE_TEXT OPT_NOTICE_LEVEL | OPT_C4 | OPT_HEAD_NOTICE | OPT_APP_TIME | OPT_CCSEMICOLON | OPT_NEWLINE #define ERROR_TEXT OPT_ERROR_LEVEL | OPT_C5 | OPT_HEAD_ERROR | OPT_APP_TIME | OPT_APP_LOCATION | OPT_CCSEMICOLON | OPT_NEWLINE #define ALWAYS_TEXT OPT_ALWAYS_LEVEL | OPT_NEWLINE | OPT_APP_TIME #define CATEGORY_OPT OPT_WARNING_LEVEL | OPT_C3 | OPT_APP_TIME #define SECTION_OPT OPT_NOTICE_LEVEL | OPT_APP_TIME #define SECTION_OPT_OK OPT_NOTICE_LEVEL | OPT_C4 | OPT_IGNORE_INDENT | OPT_CCSEMICOLON | OPT_APP_TIME #define SECTION_OPT_FAIL OPT_NOTICE_LEVEL | OPT_C5 | OPT_IGNORE_INDENT | OPT_CCSEMICOLON | OPT_APP_TIME //Configuration is found in the CPP file //Constants you can use: /* ****For use with Message Options**** OPT_DEBUG_LEVEL = debug level message OPT_WARNING_LEVEL = warning level message OPT_NOTICE_LEVEL = notice level message OPT_ERROR_LEVEL = error level message OPT_ALWAYS_LEVEL = always log message OPT_C1 = use color 1 OPT_C2 = use color 2 OPT_C3 = use color 3 OPT_C4 = use color 4 OPT_C5 = use color 5 OPT_C6 = use color 6 OPT_C7 = use color 7 OPT_C8 = use color 8 OPT_HEAD_DEBUG = use the debug message header OPT_HEAD_WARNING = use the warning message header OPT_HEAD_NOTICE = use the notice message header OPT_HEAD_ERROR = use the error message header OPT_HEAD_ALWAYS = use the always message header OPT_APP_TIME = append a time stamp to the message OPT_APP_LOCATION = append a location stamp to the message OPT_IGNORE_INDENT = ignore any category indentation OPT_NEWLINE = append a newline character to the end of the message OPT_CCSEMICOLON = change to color 2 after encountering a : ****For use with logging level*** You can specify any combination. LOG_DEBUGS = Log debug messages LOG_WARNINGS = Log warning messages LOG_NOTICES = Log notice messages LOG_ERRORS = Log error messages LOG_DISABLED = Do not log anything! Note: Messages using the OPT_ALWAYS_LEVEL will still be logged LOG_ALL = Log everything */ /////////////////////////////////////////////// //You probably shouldn't touch below this line using namespace std; //MACROS for the logging class. //New macros! xD #define LOCATION SetLocation(__FILE__, __FUNCTION__, __LINE__, 0) struct SECTION { char section[300]; float time; }; struct FILEHEADER { char program[150]; char version[50]; }; class GWLPLog { public: GWLPLog(); long Open(char* pFilename, unsigned char logLevel); void Close(); void WriteRaw(char* pString, bitset<32> options); void WriteCategory(char* pString, bitset<32> options); void WriteCategory(char* pString); void Write(bitset<32> options, const char* pString, ...); void Section(const char* pString, bitset<32> options); void SectionOk(bitset<32> options); void SectionFail(bitset<32> options); void Section(const char* pString); void SectionOk(); void SectionFail(); void StepUpCategory(); void SetLocation(const char *pFile, const char* pFunction, unsigned long line, const char* pName); //Set default options void SetSpecialDefaults(bitset<32> catOptions, bitset<32> section, bitset<32> sectionOK, bitset<32> sectionFAIL); void SetLevelDefaults(bitset<32> debugOptions, bitset<32> warningOptions, bitset<32> noticeOptions, bitset<32> errorOptions, bitset<32> alwaysOptions); //These functions will use the default options specified in the above functions void debug(const char* pString, ...); void warning(const char* pString, ...); void notice(const char* pString, ...); void error(const char* pString, ...); void always(const char* pString, ...); //This function sets the file header variables void SetFileHeader(char* pProgram, char* pVersion); //Functions now moved to this class void LogUnknownPacket(void* pData, long dataSize); void LogKnownData(char* pName, unsigned char* pData, int dataSize); void BinaryDump(char* pFile, void* pData, int dataSize); private: void LogOnlyDisplayable(unsigned char* pString, int length); bool Init(char* pFile); //Private variables ofstream* mpFout; unsigned char mLogLevel; long mIndentation; bool mUsedHeader; list
mSectionStack; FILEHEADER mFileHeader; //Used as default bitsets bitset<32> mCategoryOptions; bitset<32> mSectionOptions; bitset<32> mSectionOkOptions; bitset<32> mSectionFailOptions; bitset<32> mDebugOptions; bitset<32> mWarningOptions; bitset<32> mNoticeOptions; bitset<32> mErrorOptions; bitset<32> mAlwaysOptions; //Used for location stamp char mPFile[150]; long mLine; char mLocFunction[150]; char mPName[150]; };