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

peon::FileLogger Class Reference

This object is just used to output any needed log messages to a file. More...

#include <FileLogger.h>

Inheritance diagram for peon::FileLogger:

peon::ISingleton< FileLogger > List of all members.

Public Member Functions

 FileLogger (int log_flag=PEON_LOG_DEBUG)
 Constructor.
 ~FileLogger ()
 Destructor.
bool openLogStream (const String &strName)
 This method simply opens the file handle and prepares the log file for writing.
void closeLogStream (void)
 This method is responsible for shutting down our logging and closing any file handles.
void logInfo (const String &strObject, const String &strText)
 This method logs a string setting it to "Info" mode.
void logDebug (const String &strObject, const String &strText)
 This method logs a string setting it to "Debug" mode.
void logError (const String &strObject, const String &strText)
 This method logs a string setting it to "Error" mode.
void logFatal (const String &strObject, const String &strText)
 This method logs a string setting it to "Fatal" mode.

Static Public Member Functions

static FileLoggergetSingleton (void)
 Override standard Singleton retrieval.
static FileLoggergetSingletonPtr (void)
 Override standard Singleton retrieval.

Protected Member Functions

void writeToLogStream (const String &strText)
 This method is responsible for writing out text to our logfile.

Protected Attributes

std::ofstream m_log_file
 the file handle
String m_strLogName
 name of the file
int m_logging_level
 our logging level or filter

Detailed Description

This object is just used to output any needed log messages to a file.

We COULD make this fancier (like a primitive Log4J solution) by perhaps creating a LogInterface superclass, which we can then derive FileLogger from. This would then allow us to also create an SMTPLogger or HTMLLogger for example (to output our log messages over SMTP or into a nice and purty HTML document).

I made derived it from the ISingleton object in order to be accessible pretty much everywhere in our game and/or Peon.


Constructor & Destructor Documentation

peon::FileLogger::FileLogger int  log_flag = PEON_LOG_DEBUG  ) 
 

Constructor.

Parameters:
log_flag - the logging filter level


Member Function Documentation

void peon::FileLogger::closeLogStream void   ) 
 

This method is responsible for shutting down our logging and closing any file handles.

Parameters:
void 
Returns:
void

static FileLogger& peon::FileLogger::getSingleton void   )  [static]
 

Override standard Singleton retrieval.

Remarks:
Why do we do this? Well, it's because the Singleton implementation is in a .h file, which means it gets compiled into anybody who includes it. This is needed for the Singleton template to work, but we actually only want it compiled into the implementation of the class based on the Singleton, not all of them. If we don't change this, we get link errors when trying to use the Singleton-based class from an outside dll.
This method just delegates to the template version anyway, but the implementation stays in this single compilation unit, preventing link errors.

Reimplemented from peon::ISingleton< FileLogger >.

static FileLogger* peon::FileLogger::getSingletonPtr void   )  [static]
 

Override standard Singleton retrieval.

Remarks:
Why do we do this? Well, it's because the Singleton implementation is in a .h file, which means it gets compiled into anybody who includes it. This is needed for the Singleton template to work, but we actually only want it compiled into the implementation of the class based on the Singleton, not all of them. If we don't change this, we get link errors when trying to use the Singleton-based class from an outside dll.
This method just delegates to the template version anyway, but the implementation stays in this single compilation unit, preventing link errors.

Reimplemented from peon::ISingleton< FileLogger >.

void peon::FileLogger::logDebug const String &  strObject,
const String &  strText
 

This method logs a string setting it to "Debug" mode.

It then compares it with the internal log setting to see if it should be recorded or not.

Parameters:
strObject - object making logging call
strText - text to output

void peon::FileLogger::logError const String &  strObject,
const String &  strText
 

This method logs a string setting it to "Error" mode.

It then compares it with the internal log setting to see if it should be recorded or not.

Parameters:
strObject - object making logging call
strText - text to output

void peon::FileLogger::logFatal const String &  strObject,
const String &  strText
 

This method logs a string setting it to "Fatal" mode.

It then compares it with the internal log setting to see if it should be recorded or not.

Parameters:
strObject - object making logging call
strText - text to output

void peon::FileLogger::logInfo const String &  strObject,
const String &  strText
 

This method logs a string setting it to "Info" mode.

It then compares it with the internal log setting to see if it should be recorded or not.

Parameters:
strObject - object making logging call
strText - text to output

bool peon::FileLogger::openLogStream const String &  strName  ) 
 

This method simply opens the file handle and prepares the log file for writing.

Parameters:
std::string - our desired filename
Returns:
bool - true if we succeeded, error code otherwise

void peon::FileLogger::writeToLogStream const String &  strText  )  [protected]
 

This method is responsible for writing out text to our logfile.

Parameters:
String - our desired text to append
Returns:
void


The documentation for this class was generated from the following file:
Generated on Thu Dec 1 01:55:41 2005 for Peon by  doxygen 1.4.1