Main Page | Class List | File List | Class Members

UnwrittenLogfile Class Reference

Handle a logfile to write debug information into. More...

#include "UnwrittenLogfile.hpp"

List of all members.

Public Types

enum  UnwrittenLoggingType { UnwrittenDebug, UnwrittenInformation, UnwrittenWarning, UnwrittenError }

Public Member Functions

void Write (UnwrittenLoggingType typeOfMsg, const char *szText,...)
void WriteLine (UnwrittenLoggingType typeOfMsg, const char *szText,...)
UnwrittenLoggingType GetLoggingType ()
void Flush ()
void SetLoggingType (UnwrittenLoggingType newLoggingType)

Protected Member Functions

 UnwrittenLogfile (const std::string &szFilename, bool bPrintMessageType)
virtual ~UnwrittenLogfile ()
virtual void Dispose ()
void PrintMessageType (UnwrittenLoggingType typeOfMessage)

Friends

class UnwrittenLogfileManager


Detailed Description

Handle a logfile to write debug information into.

Author:
Tim Hütz <matrix--@users.sourceforge.net>
Date:
01/26/2005
This class can not be created diretly. The UnwrittenLogfile object should be created by using the manager class.

Definition at line 43 of file UnwrittenLogfile.hpp.


Member Enumeration Documentation

enum UnwrittenLogfile::UnwrittenLoggingType
 

The UnwrittenLoggingType enumeration is ued to select the mode which the logging engine (or only the logfile) should use for logging.

Enumeration values:
UnwrittenDebug  Write a debug message
UnwrittenInformation  Write a information message
UnwrittenWarning  Write a warning
UnwrittenError  Write a error message

Definition at line 52 of file UnwrittenLogfile.hpp.

00053                         {
00054                                 UnwrittenDebug,       
00055                                 UnwrittenInformation, 
00056                                 UnwrittenWarning,     
00057                                 UnwrittenError        
00058                         };


Constructor & Destructor Documentation

UnwrittenLogfile::UnwrittenLogfile const std::string &  szFilename,
bool  bPrintMessageType
[protected]
 

Parameters:
szFilename 
bPrintMessageType 

Definition at line 24 of file UnwrittenLogfile.cpp.

00025 {
00026         // set the needed internal variables
00027         this->m_bDisposed = false;
00028         this->m_bWaitForNewLine = false;
00029         this->m_bPrintMessageType = bPrintMessageType;
00030         this->m_szLogfileName = szFilename;
00031         this->m_eLoggingType = UnwrittenDebug;
00032 
00033         // try to open the given file
00034         if( NULL == ( this->m_pFileHandle = fopen( szFilename.c_str(), "w+" ) ) )
00035                 throw new std::exception( std::string( "Cannot create the requested logfile '" + szFilename + "'. Maybe you have no rights to write to the given location!" ).c_str() );
00036 }

UnwrittenLogfile::~UnwrittenLogfile  )  [protected, virtual]
 

Definition at line 38 of file UnwrittenLogfile.cpp.

00039 {
00040         // the dispose function should be called before calling
00041         // the destructor. If this is a debug bild, assert if 
00042         // if Dispose function was already called
00043         assert( true == this->m_bDisposed );
00044 
00045         // if the object is not dispoed at this time, call
00046         // the dispose event by myself ^^
00047         if( !this->m_bDisposed )
00048                 this->Dispose();
00049 }


Member Function Documentation

void UnwrittenLogfile::Dispose  )  [protected, virtual]
 

The Dispose function is called by the manager class to finnalize this object and to close all file handles (do *NOT* confound it with the destructor).

Definition at line 51 of file UnwrittenLogfile.cpp.

00052 {
00053         // if the logfile is opened, flush the buffer and close the file
00054         if( this->m_pFileHandle != NULL )
00055         {
00056                 fflush( this->m_pFileHandle );
00057                 fclose( this->m_pFileHandle );
00058                 this->m_pFileHandle = NULL;
00059         }
00060 
00061         // this object was disposed
00062         this->m_bDisposed = true;
00063 }

void UnwrittenLogfile::Flush  ) 
 

With this function you are able to flush the internal buffer for this class.

Definition at line 145 of file UnwrittenLogfile.cpp.

00146 {
00147         // check if the handle is not NULL
00148         assert( this->m_pFileHandle != NULL );
00149 
00150         // flush the buffer
00151         fflush( this->m_pFileHandle );
00152 }

UnwrittenLogfile::UnwrittenLoggingType UnwrittenLogfile::GetLoggingType  ) 
 

Returns:
With this function you are able to get the current logging type for this logfile.

Definition at line 65 of file UnwrittenLogfile.cpp.

00066 {
00067         return( this->m_eLoggingType );
00068 }

void UnwrittenLogfile::PrintMessageType UnwrittenLoggingType  typeOfMessage  )  [protected]
 

This function is call by Write & WriteLine to print the current message type. The function decide while calling if the message type will be printed into the logfile.

Definition at line 75 of file UnwrittenLogfile.cpp.

00076 {
00077         switch( typeOfMessage )
00078         {
00079                 case UnwrittenDebug:
00080                         fprintf( this->m_pFileHandle, "[DEBUG]       " );
00081                         break;
00082                 case UnwrittenInformation:
00083                         fprintf( this->m_pFileHandle, "[INFORMATION] " );
00084                         break;
00085                 case UnwrittenWarning:
00086                         fprintf( this->m_pFileHandle, "[WARNING]     " );
00087                         break;
00088                 case UnwrittenError:
00089                         fprintf( this->m_pFileHandle, "[ERROR]       " );
00090                         break;
00091         }
00092 }

void UnwrittenLogfile::SetLoggingType UnwrittenLoggingType  newLoggingType  ) 
 

Parameters:
newLoggingType With this function you are able to set the new logging type for this logfile.

Definition at line 70 of file UnwrittenLogfile.cpp.

00071 {
00072         this->m_eLoggingType = newLoggingType;
00073 }

void UnwrittenLogfile::Write UnwrittenLoggingType  typeOfMsg,
const char *  szText,
  ...
 

Parameters:
typeOfMsg 
szText 
... This function allow you to write a text into the file. No new line will be created after this text.

Definition at line 94 of file UnwrittenLogfile.cpp.

00095 {
00096         // the needed va_list
00097         va_list ap;
00098 
00099         // check if the handle is not NULL
00100         assert( this->m_pFileHandle != NULL );
00101 
00102         // print the given text
00103         if( typeOfMsg >= this->m_eLoggingType )
00104         {
00105                 // print the message type (if the flag is set)
00106                 if( this->m_bPrintMessageType && !this->m_bWaitForNewLine )
00107                         this->PrintMessageType( typeOfMsg );
00108 
00109                 // print the message
00110                 va_start( ap, szText );
00111                 vfprintf( this->m_pFileHandle, szText, ap );
00112                 va_end( ap );
00113 
00114                 // say that we wait for a new line
00115                 this->m_bWaitForNewLine = true;
00116         }
00117 }

void UnwrittenLogfile::WriteLine UnwrittenLoggingType  typeOfMsg,
const char *  szText,
  ...
 

Parameters:
typeOfMsg 
szText 
... This function allow you to write a text into the file. A new line will be created after this text.

Definition at line 119 of file UnwrittenLogfile.cpp.

00120 {
00121         // the needed va_list
00122         va_list ap;
00123 
00124         // check if the handle is not NULL
00125         assert( this->m_pFileHandle != NULL );
00126 
00127         // print the given text with an tailing \n
00128         if( typeOfMsg >= this->m_eLoggingType )
00129         {
00130                 // print the message type (if the flag is set)
00131                 if( this->m_bPrintMessageType && !this->m_bWaitForNewLine )
00132                         this->PrintMessageType( typeOfMsg );
00133 
00134                 // print the message
00135                 va_start( ap, szText );
00136                 vfprintf( this->m_pFileHandle, szText, ap );
00137                 fprintf( this->m_pFileHandle, "\n" );
00138                 va_end( ap );
00139         }
00140 
00141         // a new line was written
00142         this->m_bWaitForNewLine = false;
00143 }


Friends And Related Function Documentation

friend class UnwrittenLogfileManager [friend]
 

The manager class can access the protected elements of this class

Definition at line 64 of file UnwrittenLogfile.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Feb 27 19:49:00 2005 for Unwritten - Independet Logging Library by  doxygen 1.4.1