Main Page   Namespace List   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Log Class Reference

#include <log.h>

List of all members.

Public Methods

 Log (string &r_fname)
 Log (const char *fname)
 ~Log ()
void Write (const string &r_msg)
void Write (const char *fmt,...)
void SetActive (bool b)
bool IsActive ()

Private Methods

 Log (Log &)
Log & operator= (Log &)
void SetTime ()

Private Attributes

string mFileName
 log's filename or empty if cout (console)

ofstream * mpFile
 file stream or null if cout (console)

bool mActive
 flag indicating if logging is on or off

char mTimeStamp [40]
 current timestamp formatted
See also:
SetTime


CRITICAL_SECTION mMutex
 To enforce mutual exclusion.


Detailed Description

The Log class implements a simple logging mechanism to either a file stream, or to the cout console stream depending on whether constructed with a valid filename or empty filename (cout). Logging can be turned on and off by calling IsActive.

Warning:
I'm not sure if all streams are threadsafe, therefore it would be prudent not to set up separate Logs for each subsystem.
Todo:
Add different levels of logging, e.g. debug, trace, error, warning, info. Quite possibly performance instrumentation could belong in this class.

Definition at line 30 of file log.h.


Constructor & Destructor Documentation

Log::Log (  string &    r_fname ) 
 

Constructor for Log.

Parameters:
r_fname  A string that names the file to open. An empty string causes cout to be used for logging.
Todo:
Log is opened by default in append mode. A possible feature is to implement a overwrite/append toggle and/or automated log archival.

Definition at line 27 of file log.cpp.

References mActive, mFileName, mMutex, and mpFile.

Log::Log (  const char *    fname ) 
 

Constructor for Log.

Parameters:
fname  A pointer to a char array that names the file to open. An empty string causes cout to be used for logging.
Todo:
Log is opened by default in append mode. A possible feature is to implement a overwrite/append toggle and/or automated log archival.

Definition at line 48 of file log.cpp.

References mActive, mFileName, mMutex, and mpFile.

Log::~Log (    ) 
 

Log destructor.

Definition at line 62 of file log.cpp.

References mMutex, and mpFile.

Log::Log (  Log &    )  [private]
 


Member Function Documentation

bool Log::IsActive (    ) 
 

IsActive queries the whether logging is on or off.

Returns :
true if logging is on active, false if logging off.

Definition at line 147 of file log.cpp.

References mActive, and mMutex.

Log& Log::operator= (  Log &    )  [private]
 

void Log::SetActive (  bool    b ) 
 

SetActive turns logging on or off.

Parameters:
b  true sets logging on, false sets logging off.

Definition at line 137 of file log.cpp.

References mActive, and mMutex.

void Log::SetTime (    )  [private]
 

SetTime refreshes the log timestamp with the current time.

Todo:
Could be enhanced by allowing the timestamp format to be specfified in the constructor or via a setter.

Definition at line 77 of file log.cpp.

References mTimeStamp.

Referenced by Write().

void Log::Write (  const char *    fmt,
...   
) 
 

Write a formatted message to the log.

Parameters:
fmt  A character array containing format specifiers of the message to be written.
...  Zero or more parameters depending on to the number of format specifiers used in fmt.
Warning:
Like printf, using the wrong number or types of format specifiers can and will be fatal.
Bug:
Log messages that exceed 1024 characters after formatting will crash.

Definition at line 115 of file log.cpp.

References mMutex, mpFile, mTimeStamp, and SetTime().

void Log::Write (  const string &    r_msg ) 
 

Write a string message to the log.

Parameters:
r_msg  A string containing the message to be written.

Definition at line 89 of file log.cpp.

References mMutex, mpFile, mTimeStamp, and SetTime().

Referenced by Server::AcceptConnection(), Server::Boot(), Connection::Disconnect(), Connection::HandleInput(), Connection::HandleOutput(), main(), Server::Run(), Server::SetNonBlocking(), and Server::ShutdownServer().


Member Data Documentation

bool Log::mActive [private]
 

flag indicating if logging is on or off

Definition at line 46 of file log.h.

Referenced by IsActive(), Log(), and SetActive().

string Log::mFileName [private]
 

log's filename or empty if cout (console)

Definition at line 44 of file log.h.

Referenced by Log().

CRITICAL_SECTION Log::mMutex [private]
 

To enforce mutual exclusion.

Definition at line 48 of file log.h.

Referenced by IsActive(), Log(), SetActive(), Write(), and ~Log().

ofstream* Log::mpFile [private]
 

file stream or null if cout (console)

Definition at line 45 of file log.h.

Referenced by Log(), Write(), and ~Log().

char Log::mTimeStamp[40] [private]
 

current timestamp formatted

See also:
SetTime

Definition at line 47 of file log.h.

Referenced by SetTime(), and Write().


The documentation for this class was generated from the following files:
Generated on Mon Mar 29 23:12:57 2004 for Paradigm by doxygen1.2.17