Click here to Skip to main content
15,894,740 members
Articles / Programming Languages / C++

SS_Log: Fast program logging and tracing class

Rate me:
Please Sign up or sign in to vote.
4.84/5 (32 votes)
24 Apr 200321 min read 427K   4.1K   125  
Easily trace and log program flow. Allows multiple filters, multiple destinations (file, nt event log, etc), and it's fast!
// ----------------------------------------------------------------------- //
//
//  FILENAME:	sslogoutput.h
//  AUTHOR:		Steve Schaneville
//  CREATED:	13 Feb 2003, 12:44
//
//  PURPOSE:	
//
//  Copyright (c) 2003
//
// ----------------------------------------------------------------------- //
#ifndef __sslogoutput_h__
#define __sslogoutput_h__

// ------------------[       Pre-Include Defines       ]------------------ //
// ------------------[          Include Files          ]------------------ //
// ------------------[       Forward Declarations      ]------------------ //
class SSLogDestination;

// ------------------[          Macros/Defines         ]------------------ //
typedef SS_List<SSLogDestination*>              DestList;
typedef SS_List<SSLogDestination*>::Iterator    DestListIT;

// ------------------[      Constants/Enumerations     ]------------------ //
// ------------------[         Global Variables        ]------------------ //
// ------------------[         Global Functions        ]------------------ //
VOID CALLBACK TimerProcOutput(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime);

// ------------------[             Classes             ]------------------ //

// ----------------------------------------------------------------------- //
//  Class:			SSLogOutput
//  Author:			Steve Schaneville
//  Notes:			
// ----------------------------------------------------------------------- //
class SSLogOutput
{
public:

    // construction, destruction
	SSLogOutput                                     ();
	virtual ~SSLogOutput                            ();

    // assignment, copy
	SSLogOutput				    		            (SSLogOutput& rhs);

protected:

    // initialization
    virtual VOID	        InitObject		        ();

public:

	// accessor functions
    BOOL                    Dirty                   ();
    VOID                    Dirty                   (BOOL bDirty);
    UINT                    TimerID                 ();
    VOID                    TimerID                 (UINT nTimerID);
    VOID                    SetMainWindow			(CWnd* pWnd);

    DestList&               DestinationList         ();
    MsgList&                MessageList             ();

    // utilities
    BOOL                    CreateDispatchTimer     ();
    BOOL                    DispatchMessages        ();
    BOOL                    PushMessage             (LOGMESSAGE* pMsg);

protected:

    // accessor functions
    INT                     CurrentDispatchID       ();
    VOID                    CurrentDispatchID       (INT nCurrentDispatchID);
    BOOL                    UsingWindow				();
    VOID                    UsingWindow				(BOOL bUsingWindow);
    CWnd*                   MainWindow				();

	// utilities
	BOOL					InitializeDestinations	();
	BOOL					CreateDestination		(DESTINATION_TYPE nType);

    BOOL                    CurrentlyOutputting		();
    VOID                    CurrentlyOutputting		(BOOL bCurrentlyOutputting);


private:

	// make sure this operator is not called... our implementation is useless.
	SSLogOutput&			operator =		        (SSLogOutput& rhs);

	// member variables 
    BOOL				m_bDirty;
    UINT				m_nTimerID;
    BOOL				m_bUsingWindow;

    DestList			m_DestinationList;
    MsgList				m_MessageList;

    INT					m_nCurrentDispatchID;

    CWnd*				m_pMainWnd;
    CRITICAL_SECTION    m_cs;

	BOOL				m_bCurrentlyOutputting; // ;)

};


// ----------------------------------------------------------------------- //
//  SSLogOutput Inline Functions
// ----------------------------------------------------------------------- //

inline BOOL SSLogOutput::Dirty()
{ return m_bDirty; }

inline VOID SSLogOutput::Dirty(BOOL bDirty)
{ InterlockedExchange( (LPLONG)&m_bDirty, (LONG)bDirty ); }

inline UINT SSLogOutput::TimerID()
{ return m_nTimerID; }

inline VOID SSLogOutput::TimerID(UINT nTimerID)
{ m_nTimerID = nTimerID; }

inline DestList& SSLogOutput::DestinationList()
{ return m_DestinationList; }

inline MsgList& SSLogOutput::MessageList()
{ return m_MessageList; }

inline INT SSLogOutput::CurrentDispatchID()
{ return m_nCurrentDispatchID; }

inline VOID SSLogOutput::CurrentDispatchID(INT nCurrentDispatchID)
{ m_nCurrentDispatchID = nCurrentDispatchID; }

inline CWnd* SSLogOutput::MainWindow()
{ return m_pMainWnd; }

inline VOID SSLogOutput::SetMainWindow(CWnd* pWnd)
{ m_pMainWnd = pWnd; }

inline BOOL SSLogOutput::UsingWindow()
{ return m_bUsingWindow; }

inline VOID SSLogOutput::UsingWindow(BOOL bUsingWindow)
{ m_bUsingWindow = bUsingWindow; }

inline BOOL SSLogOutput::CurrentlyOutputting()
{ return m_bCurrentlyOutputting; }

inline VOID SSLogOutput::CurrentlyOutputting(BOOL bCurrentlyOutputting)
{ m_bCurrentlyOutputting = bCurrentlyOutputting; }


#endif // __sslogoutput_h__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect Amedisys
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions