Main Page | Class List | Directories | File List | Class Members | File Members

CLogger Class Reference

Tiny logging class. More...

#include <CLogger.h>

List of all members.

Public Member Functions

 CLogger (char *_pcLogFileName)
FILE * FileHandle (void) const
void LogEnd (void)
void LogError (const char *_pcFormat,...)
char * LogFileName (void) const
void LogFunction (const char *_pcFormat,...)
void LoggingEnabled (bool _bLog)
bool LoggingEnabled (void) const
void LogMessage (const char *_pcFormat,...)
void LogStart (void)
 ~CLogger ()

Private Member Functions

void LogEntry (const char *_pcFormat,...)

Private Attributes

char m_acTemp [512]
bool m_bLoggingEnabled
FILE * m_hLogFile
char * m_pcLogFileName


Detailed Description

Tiny logging class.

This can be used from anywhere to either write XML to a global log file (see: g_pGlobalLog), or use a local instantiation for (for example) specific object/class logs (or whatever, really!). This is obviously not a singleton.

Definition at line 58 of file CLogger.h.


Constructor & Destructor Documentation

CLogger char *  pcLogFileName  ) 
 

Consturctor. Opens/creates the logfile, writes the header.

Parameters:
pcLogFileName Filename for the logfile.

Definition at line 83 of file CLogger.cpp.

References LoggingEnabled(), LogMessage(), LogStart(), m_hLogFile, and m_pcLogFileName.

00084 {
00085         m_pcLogFileName = new char [ strlen(pcLogFileName) + 1 ];
00086         strcpy(m_pcLogFileName, pcLogFileName);
00087         m_hLogFile = fopen(m_pcLogFileName, "w");
00088         LogStart();
00089         LogMessage("Log Started.");
00090         LoggingEnabled(true);   
00091 }

Here is the call graph for this function:

~CLogger  ) 
 

Destructor. Close the file and cleanup.

Definition at line 122 of file CLogger.cpp.

References m_hLogFile.

00123 {
00124         fclose(m_hLogFile);
00125         delete m_pcLogFileName;
00126 }


Member Function Documentation

FILE* FileHandle void   )  const [inline]
 

Definition at line 68 of file CLogger.h.

00068 {return m_hLogFile;}

void LogEnd void   ) 
 

Writes the footer for the log XML.

Definition at line 111 of file CLogger.cpp.

References LogEntry().

00112 {
00113         LogEntry("</log>\n");
00114 }

Here is the call graph for this function:

void LogEntry const char *  pcFormat,
  ...
[private]
 

Writes a log entry to the file, copies format of printf. Called by LogMessage(), LogError() and LogFunction().

Parameters:
pcFormat,... Standard printf() style arguments.

Definition at line 152 of file CLogger.cpp.

References m_acTemp, and m_hLogFile.

Referenced by LogEnd(), LogError(), LogFunction(), LoggingEnabled(), LogMessage(), and LogStart().

00153 {       
00154         if(m_hLogFile==0)
00155                 return;
00156 
00157         int iLen;
00158 
00159         va_list argList;
00160 
00161         va_start(argList, pcFormat);
00162         iLen = vsprintf(m_acTemp, pcFormat, argList);
00163         va_end(argList);
00164 
00165         fprintf(m_hLogFile, m_acTemp);
00166 }

void LogError const char *  pcFormat,
  ...
 

Writes a error log entry to the file, copies format of printf.

Parameters:
pcFormat,... Standard printf() style arguments.

Definition at line 227 of file CLogger.cpp.

References LogEntry().

00228 {
00229         if(!m_bLoggingEnabled)
00230                 return;
00231 
00232         int iLen;
00233 
00234         va_list argList;
00235         char acTemp[256];
00236 
00237         va_start(argList, pcFormat);
00238         iLen = vsprintf(acTemp, pcFormat, argList);
00239         va_end(argList);
00240 
00241         LogEntry("<error text=\"%s\" />\n", acTemp);
00242 }

Here is the call graph for this function:

char* LogFileName void   )  const [inline]
 

Definition at line 67 of file CLogger.h.

00067 {return m_pcLogFileName;}

void LogFunction const char *  pcFormat,
  ...
 

Writes a function log entry to the file, copies format of printf.

Parameters:
pcFormat,... Standard printf() style arguments.

Definition at line 202 of file CLogger.cpp.

References LogEntry().

00203 {
00204         if(!m_bLoggingEnabled)
00205                 return;
00206 
00207         int iLen;
00208 
00209         va_list argList;
00210         char acTemp[256];
00211 
00212         va_start(argList, pcFormat);
00213         iLen = vsprintf(acTemp, pcFormat, argList);
00214         va_end(argList);
00215 
00216         LogEntry("<function name=\"%s\" />\n", acTemp);
00217 }

Here is the call graph for this function:

void LoggingEnabled bool  _bLog  ) 
 

Enable or disable logging for this instance.

Definition at line 134 of file CLogger.cpp.

References LogEntry(), and m_bLoggingEnabled.

00135 {
00136         m_bLoggingEnabled = _bLog;
00137         if(_bLog)
00138                 LogEntry("<message text=\"Logging Enabled.\" />\n");
00139         else
00140                 LogEntry("<message text=\"Logging Disabled.\" />\n");
00141 }

Here is the call graph for this function:

bool LoggingEnabled void   )  const [inline]
 

Definition at line 69 of file CLogger.h.

Referenced by CLogger().

00069 {return m_bLoggingEnabled;}

void LogMessage const char *  pcFormat,
  ...
 

Writes a message log entry to the file, copies format of printf.

Parameters:
pcFormat,... Standard printf() style arguments.

Definition at line 176 of file CLogger.cpp.

References LogEntry().

Referenced by CLogger().

00177 {
00178         if(!m_bLoggingEnabled)
00179                 return;
00180 
00181         int iLen;
00182 
00183         va_list argList;
00184         char acTemp[256];
00185 
00186         va_start(argList, pcFormat);
00187         iLen = vsprintf(acTemp, pcFormat, argList);
00188         va_end(argList);
00189 
00190         LogEntry("<message text=\"%s\" />\n", acTemp);
00191 }

Here is the call graph for this function:

void LogStart void   ) 
 

Writes the header to the logfile.

Definition at line 99 of file CLogger.cpp.

References LogEntry().

Referenced by CLogger().

00100 {
00101         LogEntry("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
00102         LogEntry("<log>\n");
00103 }

Here is the call graph for this function:


Member Data Documentation

char m_acTemp[512] [private]
 

Definition at line 83 of file CLogger.h.

Referenced by LogEntry().

bool m_bLoggingEnabled [private]
 

Definition at line 84 of file CLogger.h.

Referenced by LoggingEnabled().

FILE* m_hLogFile [private]
 

Definition at line 81 of file CLogger.h.

Referenced by CLogger(), LogEntry(), and ~CLogger().

char* m_pcLogFileName [private]
 

Definition at line 82 of file CLogger.h.

Referenced by CLogger().


The documentation for this class was generated from the following files:
Generated on Thu Oct 28 20:25:17 2004 for CLogger by  doxygen 1.3.9.1