Logger Class Reference

#include <Logger.h>


Public Member Functions

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

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


Member Function Documentation

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

References isInLogLevel(), m_os, and m_strHeader.

Referenced by Player::amIAgentToSaySomething(), SenseHandler::analyzeChangePlayerTypeMessage(), SenseHandler::analyzeCoachMessage(), SenseHandler::analyzeFullStateMessage(), SenseHandler::analyzeHearMessage(), SenseHandler::analyzeInitMessage(), SenseHandler::analyzeMessage(), SenseHandler::analyzePlayerMessage(), SenseHandler::analyzePlayerParamMessage(), SenseHandler::analyzePlayerTypeMessage(), SenseHandler::analyzeSeeGlobalMessage(), SenseHandler::analyzeSenseMessage(), SenseHandler::analyzeServerParamMessage(), WorldModel::calculateStateAgent(), WorldModel::calculateStateBall(), BasicPlayer::clearBall(), BasicPlayer::collideWithBall(), Connection::Connection(), WorldModel::coordinateWith(), WorldModel::createInterceptFeatures(), BasicPlayer::defendGoalLine(), Player::deMeer5(), BasicPlayer::directTowards(), WorldModel::drawCoordinationGraph(), BasicPlayer::dribble(), BasicPlayer::freezeBall(), BasicPlayer::getActiveInterceptionPointBall(), WorldModel::getDirectionOfWidestAngle(), WorldModel::getFastestInSetTo(), BasicPlayer::getInterceptionPointBall(), WorldModel::getMarkingPosition(), WorldModel::getMaxRangeUnknownPlayer(), WorldModel::getProbTackleSucceeds(), BasicPlayer::holdBall(), WorldModel::initParticlesAgent(), BasicPlayer::intercept(), BasicPlayer::interceptClose(), BasicPlayer::interceptScoringAttempt(), WorldModel::isBallHeadingToGoal(), WorldModel::isCollisionAfterCommand(), WorldModel::isFeatureRelevant(), BasicPlayer::kickBallCloseToBody(), BasicPlayer::kickTo(), Player::kickToDrible(), Player::kickToScore(), WorldModel::logCircle(), WorldModel::logCoordInfo(), WorldModel::logDrawBallInfo(), WorldModel::logDrawInfo(), WorldModel::logLine(), WorldModel::logObjectInformation(), Player::mainLoop(), BasicCoach::mainLoopNormal(), Player::makeBallInfo(), WorldModel::mapUnknownPlayers(), BasicPlayer::mark(), BasicPlayer::moveToPos(), BasicPlayer::moveToPosAlongLine(), BasicPlayer::outplayOpponent(), WorldModel::predictBallInfoAfterCommand(), WorldModel::predictCommandToInterceptBall(), WorldModel::predictCommandTurnTowards(), WorldModel::predictNrCyclesToObject(), WorldModel::predictNrCyclesToPoint(), WorldModel::processLastSeeMessage(), WorldModel::processLastSenseMessage(), WorldModel::processNewObjectInfo(), WorldModel::processPerfectHearInfoBall(), WorldModel::processPlayerMessage(), WorldModel::removeGhosts(), Player::sayBallStatus(), BasicPlayer::searchBall(), sense_callback(), stdin_callback(), BasicPlayer::turnWithBallTo(), WorldModel::updateAfterSenseMessage(), WorldModel::updateAgentAndBallAfterSense(), WorldModel::updateAll(), WorldModel::updateBallAfterKick(), WorldModel::updateBallForCollision(), and WorldModel::updateDynamicObjectForNextCycle().

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

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

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

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

Referenced by SenseHandler::analyzeFullStateMessage(), SenseHandler::analyzeHearMessage(), SenseHandler::analyzeMessage(), SenseHandler::analyzeSeeGlobalMessage(), SenseHandler::analyzeSeeMessage(), SenseHandler::analyzeSenseMessage(), Player::mainLoop(), WorldModel::updateAll(), and WorldModel::waitForNewInformation().

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

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

Referenced by ActHandler::sendCommands(), ActHandler::sendMessage(), ActHandler::sendMessageDirect(), and sigalarmHandler().

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

References m_os, and m_strSignal.

Referenced by log(), and logWithTime().

void Logger::restartTimer (  ) 

This method restarts the timer associated with this Logger.

Definition at line 226 of file Logger.cpp.

References m_timing, and Timing::restartTime().

Referenced by SenseHandler::analyzeFullStateMessage(), SenseHandler::analyzeSenseMessage(), and main().

Timing Logger::getTiming (  ) 

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

Definition at line 233 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 244 of file Logger.cpp.

References m_setLogLevels.

Referenced by log(), logFromSignal(), logWithTime(), Player::mainLoop(), BasicCoach::mainLoopNormal(), WorldModel::mapUnknownPlayers(), WorldModel::updateAfterSeeMessage(), and WorldModel::updateAll().

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 253 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 264 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 275 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 283 of file Logger.cpp.

References m_strHeader.

Referenced by Player::mainLoop().

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

References m_strHeader.

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

References m_strHeader.

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

References m_os.

Referenced by main().

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

References m_os.

Referenced by WorldModel::mapUnknownPlayers(), WorldModel::updateAfterSeeMessage(), and WorldModel::updateAll().

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

References m_setLogLevels.

Referenced by main().


Field Documentation

Timing Logger::m_timing [private]

timer to print timing information

Definition at line 132 of file Logger.h.

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

char Logger::m_buf[MAX_LOG_LINE] [private]

buffer needed by different methods

Definition at line 133 of file Logger.h.

Referenced by log(), and logWithTime().

set<int> Logger::m_setLogLevels [private]

set that contains all log levels

Definition at line 134 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 137 of file Logger.h.

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

ostream* Logger::m_os [private]

output stream to print messages to

Definition at line 138 of file Logger.h.

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

string Logger::m_strSignal [private]

temporary string for other messages

Definition at line 139 of file Logger.h.

Referenced by logFromSignal(), and logSignal().


The documentation for this class was generated from the following files:
Generated on Thu Apr 26 22:45:31 2007 for GangOfSix(GOS)-RoboCupTeamProject by  doxygen 1.5.1-p1