CWfcTrace

$Revision: 32 $

Description

This class helps to debug your programs. It prints out messages when entering and leaving functions. It automatically indents so you can see which functions called who. Normally, you will never use this class directly, you will use the macros. All messages generated by this class are sent to OutputDebugString().

The way I write and debug programs is to have lots and lots of debugging output. I prefer to have too many debug messages than too few. That way, I am sure to not miss anything. By having lots of debug output, you can see how a program really works as opposed to how you think a program works. I like having twenty pages of debugging output to sift through so I can see my bugs and the context they present themselves.

Data Members

static int Indent
This value is the number of spaces that will be printed before each line of output.
static DWORD Levels
This is a bit mask containing which of the 32 levels of debugging are turned on.
static BOOL Tracing
This boolean determines if any output will be generated. When TRUE, output (for levels that are on) will be generated. If FALSE, nothing is outputted.

Constructors

CWfcTrace( const CString& function_name, DWORD tracing_level )
You must provide the name and which level this object belongs.

Static Methods

static void TraceAllOn( void )
Turns on all 32 levels of tracing.
static void TraceAllOff( void )
Turns off all 32 levels of tracing.
static void TraceLevelOn( DWORD level )
Turns one of the 32 levels of tracing on.
static void TraceLevelOff( DWORD level )
Turns one of the 32 levels of tracing off.
static void TraceOn( void )
Allows messages to be printed.
static void TraceOff( void )
Disallows messages to be printed.

Methods

void Output( const CString& message ) const
void Output( const CString& message, const int integer ) const
void Output( const CString& message, const UINT integer ) const
void Output( const CString& message, const long a_long ) const
void Output( const CString& message, const ULONG a_long ) const
void Output( const CString& message, const LONGLONG a_long ) const
void Output( const CString& message, const ULONGLONG a_long ) const
void Output( const CString& message, const double a_double ) const
void Output( const CString& message, const CString& string ) const
void Output( const CString& message, const CObject * object ) const
void Output( const CString& message, const VOID * pointer ) const
void Output( const CString& message, const CObject& object ) const
void Output( const CString& message, const LARGE_INTEGER& value ) const
void Output( const CString& message, const ULARGE_INTEGER& value ) const
void Output( const CString& message, const RECT& value ) const
void Output( const CString& message, const POINT& value ) const
void Output( const CString& message, const SIZE& value ) const
void Output( const CString& message, const GUID& value ) const
void Output( const CString& message, const FILETIME& value ) const
void Output( const CString& message, const SYSTEMTIME& value ) const
Would you just look at all the stuff you can output! I toyed with the idea of putting more data structures (like WNDCLASS) but once you start down that road, you get very little return on investment. So, I stuck with the basic data types.
void OutputBinary( const CString& message, const ULONG a_long ) const
This allows you to dump the contents of a ULONG as bits. This is great for picking apart bit masks.
void OutputVariant( const CString& message, const VARIANT& value ) const
void OutputVariant( const CString& message, const VARIANT * value ) const
This allows you to dump the contents of a VARIANT.
void ReportError( DWORD error_code )
Translates error codes to a humanly readable string.
void ReportSocketError( DWORD error_code )
Translates error codes from TCP/IP socket API's to a humanly readable string.

Macros

Example

#include <wfc.h>

void print_message( void )
{
   WFCTRACEINIT( TEXT( "print_message()" ) );
   WFCTRACEVAL( TEXT( "Test number " ), 1 );
}

void main( void )
{
   WFCTRACEINIT( TEXT( "main()" ) );

   print_message();
}
Will produce this output:

Entering main()
   Entering print_message()
      print_message() : Test number 1
   Leaving  print_message()
Leaving  main()

API's Used

CWfcTrace uses the following API's:
Copyright, 2000, Samuel R. Blackburn
$Workfile: WfcTrace.cpp $
$Modtime: 10/10/01 3:16a $