Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Logger Class Reference

#include <Logger.h>

Collaboration diagram for Logger:

Collaboration graph
[legend]
List of all members.

Public Methods

 Logger (ostream &os=cout, int iMinLogLevel=0, int iMaxLogLevel=0)
bool log (int iLevel, string str)
bool log (int i, char *str,...)
bool logWithTime (int iLevel, char *str,...)
void restartTimer ()
bool isInLogLevel (int iLevel)
int getMinLogLevel () const
bool setMinLogLevel (int iLevel)
int getMaxLogLevel () const
bool setMaxLogLevel (int iLevel)
int getExtraLogLevel () const
bool setExtraLogLevel (int iLevel)
char * getHeader ()
bool setHeader (char *str)
bool setHeader (int i1, int i2)
bool setOutputStream (ostream &os)

Private Attributes

Timing timing
char buf [MAX_LOG_LINE]
int iMinLogLevel
int iMaxLogLevel
int iExtraLogLevel
char strHeader [MAX_HEADER]
ostream * os

Detailed Description

This class makes it possible to log information on different abstraction levels. All messages are passed to the log method 'log' with a level indication. When this level lies in the specified range (iMinLogLevel.. iMaxLogLevel) the message is logged, otherwise it is ignored. This makes it possible to print only the information you are interested in. There is one global Log class which is used by all classes that use the Logger. This instantation of the Logger is located in the file Logger.C and is called 'Log'. All classes that want use this Logger should make a reference to it using the line 'extern Logger Log;' and can then use this Logger with the Log.log( ... ) methods. Furthermore the Logger also contains a timer with makes it possible to print the time since the timer has been restarted.

Definition at line 94 of file Logger.h.


Constructor & Destructor Documentation

Logger::Logger ostream &    o = cout,
int    iMin = 0,
int    iMax = 0
 

This is the constructor for the Logger. The output stream, the minimal and maximal log level can all be specified. The timer in this class is also restarted.

Parameters:
o  outputstream (file or cout) to which information is printed (default cout)
iMin  minimal log level (default 0)
iMax  maximal log level (default 0)

Definition at line 66 of file Logger.C.

References iMaxLogLevel, iMinLogLevel, os, Timing::restartTime(), strHeader, and timing.


Member Function Documentation

int Logger::getExtraLogLevel   const
 

This method returns the extra log level. Message with a level that are equal to this value are always logged.

Returns:
minimal log level.

Definition at line 214 of file Logger.C.

References iExtraLogLevel.

char * Logger::getHeader  
 

This method returns the current header that is written before the actual text that has to be logged.

Returns:
current header

Definition at line 234 of file Logger.C.

References strHeader.

int Logger::getMaxLogLevel   const
 

This method returns the maximal log level. Message with a level that are higher than this value are ignored when they are logged.

Returns:
minimal log level.

Definition at line 196 of file Logger.C.

References iMaxLogLevel.

Referenced by isInLogLevel().

int Logger::getMinLogLevel   const
 

This method returns the minimal log level. Message with a level that lies below this value are ignored when they are logged.

Returns:
minimal log level.

Definition at line 178 of file Logger.C.

References iMinLogLevel.

Referenced by isInLogLevel().

bool Logger::isInLogLevel int    iLevel
 

This method returns whether the supplied log level is recorded, thus within the interval [min_log_level..max_log_level] or equal to the extra log level.

Parameters:
iLevel  log level that should be checked
Returns:
bool indicating whether the supplied log level is logged.

Definition at line 169 of file Logger.C.

References getMaxLogLevel(), getMinLogLevel(), and iExtraLogLevel.

Referenced by log(), and logWithTime().

bool Logger::log int    iLevel,
char *    str,
...   
 

This method can be used to log information. Only when the specified level of the message lies in the range (iMinLogLevel..iMaxLogLevel) the information is logged. This method receives a character string that may contain format specifiers that are also available to 'printf' (like d, f, etc.). The remaining arguments are the variables that have to be filled in at the location of the specifiers.

Parameters:
iLevel  level corresponding to this message
str  character string with (possible) format specifiers
...  variables that define the values of the specifiers.
Returns:
bool indicating whether the message was logged or not.

Definition at line 103 of file Logger.C.

References buf, isInLogLevel(), os, and strHeader.

bool Logger::log int    iLevel,
string    str
 

This method can be used to log information. Only when the specified level of the message lies in the range (iMinLogLevel..iMaxLogLevel) the information is logged. This method receives a a normal string

Parameters:
iLevel  level corresponding to this message
str  string that is logged when iLevel lies in the range
Returns:
bool indicating whether the message was logged or not.

Definition at line 82 of file Logger.C.

References isInLogLevel(), os, and strHeader.

Referenced by Connection::Connection().

bool Logger::logWithTime int    iLevel,
char *    str,
...   
 

This method can be used to log information. Only when the specified level of the message lies in the range (iMinLogLevel..iMaxLogLevel) the information is logged. This method receives a character string that may contain format specifiers that are also available to 'printf' (like d, f, etc.). The remaining arguments are the variables that have to be filled in at the location of the specifiers. Before the logged message the elapsed time since the timer has been restarted is printed.

Parameters:
iLevel  level corresponding to this message
str  character string with (possible) format specifiers
...  variables that define the values of the specifiers.
Returns:
bool indicating whether the message was logged or not.

Definition at line 134 of file Logger.C.

References buf, isInLogLevel(), os, Timing::printTimeDiffWithText(), strHeader, and timing.

void Logger::restartTimer  
 

This method restarts the timer associated with this Logger.

Definition at line 159 of file Logger.C.

References Timing::restartTime(), and timing.

Referenced by main().

bool Logger::setExtraLogLevel int    iLevel
 

This method sets the maximal log level. Message with a level that are higher this value are ignored when they are logged.

Parameters:
iLevel  new maximal log level.
Returns:
bool indicating whether the update was succesfull

Definition at line 223 of file Logger.C.

References iExtraLogLevel.

bool Logger::setHeader int    i1,
int    i2
 

This method sets the header that is written before the actual text that has to be logged. The header is represented by two integers which are written between parentheses.

Parameters:
i1  first integer
i2  second integer
Returns:
bool indicating whether the update was succesfull

Definition at line 255 of file Logger.C.

References strHeader.

bool Logger::setHeader char *    str
 

This method sets the header that is written before the actual text that has to be logged.

Parameters:
str  that represents the character string
Returns:
bool indicating whether the update was succesfull

Definition at line 243 of file Logger.C.

References strHeader.

bool Logger::setMaxLogLevel int    iLevel
 

This method sets the maximal log level. Message with a level that are higher this value are ignored when they are logged.

Parameters:
iLevel  new maximal log level.
Returns:
bool indicating whether the update was succesfull

Definition at line 205 of file Logger.C.

References iMaxLogLevel.

Referenced by main().

bool Logger::setMinLogLevel int    iLevel
 

This method sets the minimal log level. Message with a level that lies below this value are ignored when they are logged.

Parameters:
iLevel  new minimal log level.
Returns:
bool indicating whether the update was succesfull

Definition at line 187 of file Logger.C.

References iMinLogLevel.

Referenced by main().

bool Logger::setOutputStream ostream &    o
 

This method sets the output stream to which the log information is written. This outputstream can be standard output (cout) or a reference to a file.

Parameters:
o  outputstream to which log information is printed.
Returns:
bool indicating whether update was succesfull.

Definition at line 266 of file Logger.C.

References os.

Referenced by main().


Member Data Documentation

char Logger::buf[MAX_LOG_LINE] [private]
 

buffer needed by different methods

Definition at line 97 of file Logger.h.

Referenced by log(), and logWithTime().

int Logger::iExtraLogLevel [private]
 

extra log level to print information

Definition at line 100 of file Logger.h.

Referenced by getExtraLogLevel(), isInLogLevel(), and setExtraLogLevel().

int Logger::iMaxLogLevel [private]
 

maximal log level to print information

Definition at line 99 of file Logger.h.

Referenced by getMaxLogLevel(), Logger(), and setMaxLogLevel().

int Logger::iMinLogLevel [private]
 

minimal log level to print information

Definition at line 98 of file Logger.h.

Referenced by getMinLogLevel(), Logger(), and setMinLogLevel().

ostream* Logger::os [private]
 

output stream to print messages to

Definition at line 102 of file Logger.h.

Referenced by log(), Logger(), logWithTime(), and setOutputStream().

char Logger::strHeader[MAX_HEADER] [private]
 

header string that is printed before msg

Definition at line 101 of file Logger.h.

Referenced by getHeader(), log(), Logger(), logWithTime(), and setHeader().

Timing Logger::timing [private]
 

timer to print timing information

Definition at line 96 of file Logger.h.

Referenced by Logger(), logWithTime(), and restartTimer().


The documentation for this class was generated from the following files:
Generated on Thu Mar 7 00:37:54 2002 for UvA Trilearn 2001 by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001