Main Page   Namespace List   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,...)
bool logFromSignal (int iLevel, char *str,...)
bool logSignal ()
void restartTimer ()
Timing getTiming ()
bool isInLogLevel (int iLevel)
bool addLogLevel (int iLevel)
bool addLogRange (int iMin, int iMax)
char * getHeader ()
bool setHeader (char *str)
bool setHeader (int i)
bool setHeader (int i1, int i2)
bool setOutputStream (ostream &os)
ostream & getOutputStream ()
void showLogLevels (ostream &os)

Private Attributes

Timing m_timing
char m_buf [MAX_LOG_LINE]
set< int > m_setLogLevels
pthread_mutex_t mutex_stream
char m_strHeader [MAX_HEADER]
ostream * m_os
string m_strSignal

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 it has been specified that this level should be logged using either the 'addLogLevel' or 'addLogRange' method 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 119 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 74 of file Logger.cpp.

References addLogRange(), m_os, m_strHeader, m_timing, mutex_stream, and Timing::restartTime().


Member Function Documentation

bool Logger::addLogLevel int    iLevel
 

This method inserts the log level 'iLevel' to the set of logged levels. Information from this log level will be printed.

Parameters:
iLevel  level that will be added to the set
Returns:
bool indicating whether the update was successfull.

Definition at line 252 of file Logger.cpp.

References m_setLogLevels.

Referenced by addLogRange(), and main().

bool Logger::addLogRange int    iMin,
int    iMax
 

This method inserts all the log levels in the interval [iMin..iMax] to the set of logged levels.

Parameters:
iMin  minimum log level that is added
iMax  maximum log level that is added
Returns:
bool indicating whether the update was successfull.

Definition at line 263 of file Logger.cpp.

References addLogLevel().

Referenced by Logger(), and main().

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 274 of file Logger.cpp.

References m_strHeader.

ostream & Logger::getOutputStream  
 

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

Returns:
o outputstream to which log information is printed.

Definition at line 327 of file Logger.cpp.

References m_os.

Timing Logger::getTiming  
 

Return the instance of the timing class that denotes the time the counter is running.

Definition at line 232 of file Logger.cpp.

References m_timing.

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 243 of file Logger.cpp.

References m_setLogLevels.

Referenced by log(), logFromSignal(), logWithTime(), Player::mainLoop(), and BasicCoach::mainLoopNormal().

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

This method can be used to log information. Only when the specified level of the message is part of the set of logged values 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 111 of file Logger.cpp.

References isInLogLevel(), logSignal(), m_buf, m_os, m_strHeader, and MAX_LOG_LINE.

bool Logger::log int    iLevel,
string    str
 

This method can be used to log information. Only when the specified level of the message is part of the set of logged levels the information is logged. This method receives a a normal string that is logged.

Parameters:
iLevel  level corresponding to this message
str  string that is logged when iLevel is a logging lvel.
Returns:
bool indicating whether the message was logged or not.

Definition at line 90 of file Logger.cpp.

References isInLogLevel(), m_os, and m_strHeader.

Referenced by Connection::Connection(), BasicCoach::mainLoopNormal(), and stdin_callback().

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

This method can be used to log information. The main difference with the standard log method is that in this case the string is not printed to the output stream immediately but only at the next call of log (or logWithTime). This is a work-around for specific compiler cases in which a deadlock occurs when something is logged at the same instance by two different threads.

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 181 of file Logger.cpp.

References Timing::getElapsedTime(), isInLogLevel(), m_strHeader, m_strSignal, m_timing, and MAX_LOG_LINE.

bool Logger::logSignal  
 

This method actually writes the string that was created with logFromSignal to the specified output stream.

Returns:
bool indicating whether the message was logged or not.

Definition at line 213 of file Logger.cpp.

References m_os, and m_strSignal.

Referenced by log(), and logWithTime().

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

This method can be used to log information. Only when the specified level of the message is an element in the set of logged levels 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 143 of file Logger.cpp.

References isInLogLevel(), logSignal(), m_buf, m_os, m_strHeader, m_timing, MAX_LOG_LINE, and Timing::printTimeDiffWithText().

void Logger::restartTimer  
 

This method restarts the timer associated with this Logger.

Definition at line 225 of file Logger.cpp.

References m_timing, and Timing::restartTime().

Referenced by main().

bool Logger::setHeader int    i1,
int    i2
 

This method sets a predefined header that is written before the actual logging text. The header is represented by two integers which are written between parentheses, i.e. (9, 2401).

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

Definition at line 294 of file Logger.cpp.

References m_strHeader.

bool Logger::setHeader int    i
 

This method sets a predefined header that is written before the actual logging text. The header is represented by one integer which is followed by a semicolon (":") .

Parameters:
integer 
Returns:
bool indicating whether the update was succesfull

Definition at line 305 of file Logger.cpp.

References m_strHeader.

bool Logger::setHeader char *    str
 

This method sets the header that is written before the actual logging text.

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

Definition at line 282 of file Logger.cpp.

References m_strHeader.

Referenced by Player::mainLoop().

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 317 of file Logger.cpp.

References m_os.

Referenced by main().

void Logger::showLogLevels ostream &    os
 

This method outputs all the log levels that are logged to the output stream os.

Parameters:
os  output stream to which log levels are printed.

Definition at line 335 of file Logger.cpp.

References m_setLogLevels.

Referenced by main().


Member Data Documentation

char Logger::m_buf[MAX_LOG_LINE] [private]
 

buffer needed by different methods

Definition at line 122 of file Logger.h.

Referenced by log(), and logWithTime().

ostream* Logger::m_os [private]
 

output stream to print messages to

Definition at line 127 of file Logger.h.

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

set<int> Logger::m_setLogLevels [private]
 

set that contains all log levels

Definition at line 123 of file Logger.h.

Referenced by addLogLevel(), isInLogLevel(), and showLogLevels().

char Logger::m_strHeader[MAX_HEADER] [private]
 

header string printed before msg

Definition at line 126 of file Logger.h.

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

string Logger::m_strSignal [private]
 

temporary string for other messages

Definition at line 128 of file Logger.h.

Referenced by logFromSignal(), and logSignal().

Timing Logger::m_timing [private]
 

timer to print timing information

Definition at line 121 of file Logger.h.

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

pthread_mutex_t Logger::mutex_stream [private]
 

Definition at line 125 of file Logger.h.

Referenced by Logger().


The documentation for this class was generated from the following files:
Generated on Fri Nov 7 11:46:03 2003 for UvA Trilearn 2003 Base Code by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001