C++ common classes
General purpose classes for use across projects (Apache license)
CLogging Class Reference

CLogging.h: interface for the CLogging class. More...

#include <CLogging.h>

List of all members.

Public Types

enum  DISPLAY_MODE { D_CONSOLE = 0, D_FILE = 1, D_BOTH = 2 }
enum  { FILE_FLUSH_INTERVAL = 120 }

Public Member Functions

 CLogging (BOOL bUseFlushThread=FALSE)
 CLogging (const char *szBaseName, const char *szDir=NULL, BOOL bDayExtension=TRUE, BOOL bUseFlushThread=FALSE)
virtual ~CLogging ()
virtual BOOL InitLoggingFile (const char *szBaseName, const char *szDir=NULL, BOOL bDayExtension=TRUE)
 If day extension is TRUE, the date will be appended to the file name.
virtual BOOL InitLoggingFile (const char *szBaseName, const char *szExtenssion, const char *szDir=NULL, BOOL bDayExtension=TRUE)
 If day extension is TRUE, the date will be appended to the file name.
int WriteToLog (const char *szLine, int iLevel=0, BOOL bSuppressTimestamp=FALSE)
 Write to the log.
void SetCloseMode (BOOL bClose)
 If TRUE, will open before each write and close afterwards. Defaults to FALSE.
const char * GetFileName ()
 Returns the file name.
const char * GetFilePath ()
 Returns the full file path.
void SetOutputMode (DISPLAY_MODE eMode)
 Set display mode.
void SetFileFlushInterval (int iFlush)
 Set file flush interval (seconds)
int CloseFile ()
 Force a close file.
virtual BOOL OKtoClose ()
 See if OK to close at this point.
virtual void ChangingDay ()
 Changing day routine.
long GetFileSize ()
 Get the file size.
void SetLogLevel (int iLevel)
 Set the logging level. iLevel passed to WriteToLog must <= to be output. (0 - 99)
void PrefixTimestamp (BOOL bTime=TRUE)
 Prefix time stamp to all lines.
void SetNameChange (BOOL bChange)
 Set so file name doesn't change on a new day.
BOOL WasCreatedOnOpen ()
 Was the file created on the open?

Protected Member Functions

virtual FILE * OpenLogFile ()
 Open the file.
const char * GetTimestamp ()
 Get a timestamp string.
virtual void CloseLogFile ()
 Close the file.
void Initialize (BOOL bUseFlushThread)
 Initialize the file.
const char * CreateFileName (const char *szBaseName, const char *szDir, BOOL bDayExtension, const char *szExtension)
 Create the file name.

Protected Attributes

CFlushLogThread cFlushThread
BOOL bActivity
BOOL bTimestamp
int iLogLevel
DISPLAY_MODE eDisplayMode
BOOL bCloseMode
BOOL bDayExt
FILE * pFile
string sBaseName
string sLogFileDir
string sFileName
string sPath
int iYear
int iDayofYear
int iFileFlushInterval
CXPlatCriticalSection cCriticalSection
char szTimeStamp [64]
BOOL bNameChange
BOOL bWasCreated

Friends

class CFlushLogThread

Detailed Description

CLogging.h: interface for the CLogging class.

_MSC_VER >= 1000 CLogging implements an atomic logging capability with the additional ability to to have a separate thread to flush the log buffer to disk at programmed intervals.

Definition at line 31 of file CLogging.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
FILE_FLUSH_INTERVAL 

Definition at line 41 of file CLogging.h.

Enumerator:
D_CONSOLE 
D_FILE 
D_BOTH 

Definition at line 35 of file CLogging.h.


Constructor & Destructor Documentation

CLogging::CLogging ( BOOL  bUseFlushThread = FALSE)

Definition at line 33 of file CLogging.cpp.

CLogging::CLogging ( const char *  szBaseName,
const char *  szDir = NULL,
BOOL  bDayExtension = TRUE,
BOOL  bUseFlushThread = FALSE 
)

Definition at line 38 of file CLogging.cpp.

CLogging::~CLogging ( ) [virtual]

Definition at line 58 of file CLogging.cpp.


Member Function Documentation

void CLogging::ChangingDay ( void  ) [virtual]

Changing day routine.

Definition at line 440 of file CLogging.cpp.

Force a close file.

void CLogging::CloseLogFile ( ) [protected, virtual]

Close the file.

Definition at line 339 of file CLogging.cpp.

const char * CLogging::CreateFileName ( const char *  szBaseName,
const char *  szDir,
BOOL  bDayExtension,
const char *  szExtension 
) [protected]

Create the file name.

Definition at line 477 of file CLogging.cpp.

const char * CLogging::GetFileName ( )

Returns the file name.

Definition at line 364 of file CLogging.cpp.

const char * CLogging::GetFilePath ( )

Returns the full file path.

Definition at line 371 of file CLogging.cpp.

Get the file size.

Definition at line 387 of file CLogging.cpp.

const char * CLogging::GetTimestamp ( ) [protected]

Get a timestamp string.

Definition at line 456 of file CLogging.cpp.

void CLogging::Initialize ( BOOL  bUseFlushThread) [protected]

Initialize the file.

Definition at line 46 of file CLogging.cpp.

BOOL CLogging::InitLoggingFile ( const char *  szBaseName,
const char *  szDir = NULL,
BOOL  bDayExtension = TRUE 
) [virtual]

If day extension is TRUE, the date will be appended to the file name.

Definition at line 68 of file CLogging.cpp.

BOOL CLogging::InitLoggingFile ( const char *  szBaseName,
const char *  szExtenssion,
const char *  szDir = NULL,
BOOL  bDayExtension = TRUE 
) [virtual]

If day extension is TRUE, the date will be appended to the file name.

Definition at line 76 of file CLogging.cpp.

BOOL CLogging::OKtoClose ( void  ) [virtual]

See if OK to close at this point.

Definition at line 435 of file CLogging.cpp.

FILE * CLogging::OpenLogFile ( ) [protected, virtual]

Open the file.

Definition at line 128 of file CLogging.cpp.

Prefix time stamp to all lines.

Definition at line 448 of file CLogging.cpp.

If TRUE, will open before each write and close afterwards. Defaults to FALSE.

Definition at line 355 of file CLogging.cpp.

Set file flush interval (seconds)

Definition at line 423 of file CLogging.cpp.

void CLogging::SetLogLevel ( int  iLevel)

Set the logging level. iLevel passed to WriteToLog must <= to be output. (0 - 99)

Definition at line 411 of file CLogging.cpp.

Set so file name doesn't change on a new day.

Set display mode.

Definition at line 379 of file CLogging.cpp.

Was the file created on the open?

Definition at line 547 of file CLogging.cpp.

int CLogging::WriteToLog ( const char *  szLine,
int  iLevel = 0,
BOOL  bSuppressTimestamp = FALSE 
)

Write to the log.

Definition at line 185 of file CLogging.cpp.


Friends And Related Function Documentation

friend class CFlushLogThread [friend]

Definition at line 33 of file CLogging.h.


Member Data Documentation

Definition at line 95 of file CLogging.h.

Definition at line 99 of file CLogging.h.

BOOL CLogging::bDayExt [protected]

Definition at line 100 of file CLogging.h.

Definition at line 111 of file CLogging.h.

Definition at line 96 of file CLogging.h.

Definition at line 112 of file CLogging.h.

Definition at line 109 of file CLogging.h.

Definition at line 94 of file CLogging.h.

Definition at line 98 of file CLogging.h.

int CLogging::iDayofYear [protected]

Definition at line 107 of file CLogging.h.

Definition at line 108 of file CLogging.h.

int CLogging::iLogLevel [protected]

Definition at line 97 of file CLogging.h.

int CLogging::iYear [protected]

Definition at line 106 of file CLogging.h.

FILE* CLogging::pFile [protected]

Definition at line 101 of file CLogging.h.

string CLogging::sBaseName [protected]

Definition at line 102 of file CLogging.h.

string CLogging::sFileName [protected]

Definition at line 104 of file CLogging.h.

string CLogging::sLogFileDir [protected]

Definition at line 103 of file CLogging.h.

string CLogging::sPath [protected]

Definition at line 105 of file CLogging.h.

char CLogging::szTimeStamp[64] [protected]

Definition at line 110 of file CLogging.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines