Usage: |
#include
"ESLogger.h"
ESLog logger;
logger.setPath("C:\temp\");
logger.setGroupName("ESLogger.testTool");
logger.traceIn("testFunction()");
logger.traceBool(ESLogger::traceLevel::debug,"My Bool Label",myBool);
logger.traceOut("testFunction()"); |
/*****************************************************************************************
USAGE:
class ESLogger
ESLogger is a singleton, actually ESLog is the functional class and ESLogger is the
intended exposed class. ESLogger is a helper class to keep track of the instances and make life
more simple for you. (really me) If you(me) only use stack instances of the ESLogger class life
will be sweet. You can still create heap instances just do nt forget to delete the instance.
An undeleted instance will become relavent once you profile, but I think that is the worst case
senerio.
ESLogger allows you to specify logging groups in a parent-child relationship
with 4 levels:
NONE - No tracing
ERROR - Only write when an unrecoverable error occurs
WARN - Write when an non-problematic error occurs, ERROR level is also included
DEBUG - This it the debug trace level, WARN and ERROR levels are also included
Group levels are stored in an ini file for easy access.
Group layout: group layout should reflect the namespace or even more granular.
example:
parent group name, "CompanyXYZ"
a child = the Product Name, "ziptoe"
with children classes, "mainDialog"
the child class "mainDialog" would be represented as "CampanyXYZ.ziptoe.mainDialog"
**** Example ini file: ****
; General settings are stored here
[ESLog]
; TraceFileName for easy customization, defaults to trace.trc Must be a relative path
; illegal : traceFile=c:\temp\traceFile
; legal : traceFile=dir1\dir2\trace.trc
; note there is no leading backslash
traceFile=trace.trc
; this will print out all trace groups in the ESLogTrace section
; a minus sign denotes that the group depends on the parents trace level
; If changed back to "NO" all the parent dependant groups will be removed.
; this is a good way to figure out what groups exist without checking code.
TraceAllLevels=YES
; all group levels are stored here. If a group is missing
; it will depend on the parents debug level. Default trace level is None
[ESLogTrace]
CompanyXYZ=Error
CompanyXYZ.ziptoe=-Error
CompanyXYZ.ziptoe.mainDialog=-Error
; NOTE the minus signs signifying dependance on the parent. It also has the DebugLevel it thinks the
; parent is to the right of minus sign. This was printed with the TraceAllLevels=YES option.
; You would not put the -{Level} in yourself, just do not include the group to set the
; paren-child dependancy
**** functions ****/
class ESLOG_API ESLogger
{
ESLog * m_logger;
string m_groupName;
int m_groupID;
public:
/* Constructors:*/
ESLogger(); // default:
ESLogger(const char* groupName); // probably no need for this as you will always use a stack instance *wink*
/* Destructors:*/
virtual ~ESLogger();
/* The debug levels and there codes */
enum traceLevel {
none = 0,
error = 1,
warn = 2,
debug = 3,
};
/* when using the default constructor you must tell the logger
// what the groups name is. ie "CompanyXYZ.ziptoe.mainDialog" */
void setGroupName(const char* groupName);
/* This is required and you must do it before anything else.
// I originally did not require this to be set */
void setPath(const char * path);
/* all (f) functions use the sprinf function example usage:
// tracef(ESLogger::traceLevel::debug,"%d %s",54,"is my lucky number");
// level : is the level you want this msg to be printed
// msg : the msg to print
// Traces without the Carriage Return / LineFeed */
__inline void rawTrace (short level, const char * msg ); // NO Carriage Return / LineFeed no Time
__inline void trace (short level, const char * msg ); // with the Carriage Return / LineFeed
__inline void traceBool (short level, const char * label, bool b); // with the Carriage Return / LineFeed
__inline void traceLong (short level, const char * label, long l);// with the Carriage Return / LineFeed
__inline void traceDouble(short level, const char * label, double d, short numDec);// with the Carriage Return / LineFeed
__inline void traceHex (short level, const char * label, unsigned long l);// with the Carriage Return / LineFeed
__inline void traceString(short level, const char * label, const char* s);// with the Carriage Return / LineFeed
void tracef(short level, LPCSTR lpszFormat , ... ); // NO Carriage Return / LineFeed : Not Inline cause much code and I think the compiler will not make it inline anyway because of the variable arguments
/* Traces with the Carriage Return / LineFeed */
// use the traceIn and traceOut functions at the beginning and end of a function
// It is extremely important to verify every In has its corrisponding Out
// trace In and Outs also keep track of profiling, IE time each function takes
// To enable this, use the _ES_TO_PROFILE by defining it above */
__inline void traceIn (const char * functionName);// with the Carriage Return / LineFeed
__inline void traceInBool (const char * functionName, const char * label ,bool b);// with the Carriage Return / LineFeed
__inline void traceInLong (const char * functionName, const char * label ,long l);// with the Carriage Return / LineFeed
__inline void traceInDouble (const char * functionName, const char * label ,double d, short numDec);// with the Carriage Return / LineFeed
__inline void traceInHex (const char * functionName, const char * label ,unsigned long l);// with the Carriage Return / LineFeed
__inline void traceInString (const char * functionName, const char * label ,const char* s);// with the Carriage Return / LineFeed
void traceInf(const char * functionName, LPCSTR lpszFormat , ... ); // Not Inline cause much code and I think the compiler will not make it inline anyway because of the variable arguments
__inline void traceOut (const char * functionName);// with the Carriage Return / LineFeed
__inline void traceOutBool (const char * functionName, const char * label ,bool b);// with the Carriage Return / LineFeed
__inline void traceOutLong (const char * functionName, const char * label ,long l);// with the Carriage Return / LineFeed
__inline void traceOutDouble(const char * functionName, const char * label ,double d, short numDec);// with the Carriage Return / LineFeed
__inline void traceOutHex (const char * functionName, const char * label ,unsigned long l);// with the Carriage Return / LineFeed
__inline void traceOutString(const char * functionName, const char * label ,const char* s);// with the Carriage Return / LineFeed
void traceOutf(const char * functionName, LPCSTR lpszFormat , ... ); // Not Inline cause much code and I think the compiler will not make it inline anyway because of the variable arguments
/* In some cases you may want more control over printing to the file
// you can use it like this:
// if(HANDLE file = logger.openTraceFile(ESLogger::traceLevel::debug)){
// size_t stringLngth;
// DWORD wordwritten;
//
// stringLngth = strlen(msg);
// writeFile(file, "I write funny messages", stringLngth, &wordwritten, 0);
// logger.closeTraceFile();
// }*/
__inline HANDLE openTraceFile( short level );
__inline void closeTraceFile();
/* Some functions are called way to much but you may want to profile them
// so use these functions instead of the traceIn/Out functions*/
__inline void profileIn(const char * functionName);
__inline void profileOut(const char * functionName);
/*****************************************************************************************/
};
#endif
|