LAMA
lama::Logger Class Reference

A logger abstraction. More...

#include <Logger.hpp>

Inheritance diagram for lama::Logger:

Public Member Functions

const std::string & id () const
 Returns the id of this.
 Logger (const std::string &id, LogLevel::LogLevel level, LoggerWriteBehaviour::LoggerWriteBehaviour writeBehaviour, bool ignoreRank=false)
 Creates a logger with the specified properties.
 Logger (const std::string &id, LogLevel::LogLevel level, LoggerWriteBehaviour::LoggerWriteBehaviour writeBehaviour, std::auto_ptr< Timer > timer, bool ignoreRank=false)
 Creates a logger with the specified properties.
 Logger (const std::string &id, LogLevel::LogLevel level, LoggerWriteBehaviour::LoggerWriteBehaviour writeBehaviour, const std::string &logFileName, std::auto_ptr< Timer > timer, bool ignoreRank=false)
 Creates a logger with the specified properties.
virtual ~Logger ()
 Destructor.
LogLevel::LogLevel getLogLevel () const
 Returns the log level of this logger.
void setLogLevel (LogLevel::LogLevel level)
 Sets the internal LogLevel.
void logMessage (LogLevel::LogLevel level, const std::string &message)
 Logs a user specified message.
void logNewLine (LogLevel::LogLevel level)
 Logs an empty line.
void logResidual (LogLevel::LogLevel level, const Solver &solver, const Norm &norm, const std::string iterationPrefix="")
 Logs the residual of the solver.
void logTime (const std::string &timerId, LogLevel::LogLevel level, const std::string &message)
 logs the elapsed time in combination with a user-specified message.
void startTimer (const std::string &timerId)
 Starts an internal timer of the logger.
void stopTimer (const std::string &timerId)
 Stops an internal timer of the logger.
void stopAndResetTimer (const std::string &timerId)
 Stops and resets an internal timer.
template<typename T >
void logType (LogLevel::LogLevel level, const std::string &message, T arg)
 logs a message followed by an custom type by using the << operator.

Protected Member Functions

virtual void logString (LogLevel::LogLevel level, const std::string &message)
 Performs a LogLevel check and logs the message depending on this.
virtual void logString (const std::string &message)
 Logs the message.
virtual std::string createPrefix ()=0
 Template-Pattern Method - used by subclasses to create a prefix which will be added to each message.
 LAMA_LOG_DECL_STATIC_LOGGER (logger)

Protected Attributes

std::auto_ptr< TimermTimer
 Timer used for timings.
std::string mId

Private Attributes

LogLevel::LogLevel mLogLevel
LoggerWriteBehaviour::LoggerWriteBehaviour mWriteBehaviour
bool mIgnoreRank

Detailed Description

A logger abstraction.

This class represents a logger abstraction. It defines common logger operations. Derived classes may use the createPrefix() method to customize messages.


Constructor & Destructor Documentation

lama::Logger::Logger ( const std::string &  id,
LogLevel::LogLevel  level,
LoggerWriteBehaviour::LoggerWriteBehaviour  writeBehaviour,
bool  ignoreRank = false 
)

Creates a logger with the specified properties.

This constructor creates a common logger with the specified properties. These properties are the write behavior and the log-level. No file name for a logfile is required.

Parameters:
levelThe loglevel of the logger. Messages with a loglevel greater than the level of the logger will be omitted. Instead of a common logger with the "noLogging" loglevel a NullLogger should be used.
writeBehaviourSpecifies, if the logger shall write its output to the console and a file or to the console only

References mTimer.

lama::Logger::Logger ( const std::string &  id,
LogLevel::LogLevel  level,
LoggerWriteBehaviour::LoggerWriteBehaviour  writeBehaviour,
std::auto_ptr< Timer timer,
bool  ignoreRank = false 
)

Creates a logger with the specified properties.

This constructor creates a common logger with the specified properties. These properties are the write behavior and the log-level. No file name for a logfile is required.

Parameters:
levelThe loglevel of the logger. Messages with a loglevel greater than the level of the logger will be omitted. Instead of a common logger with the "noLogging" loglevel a NullLogger should be used.
writeBehaviourSpecifies, if the logger shall write its output to the console and a file or to the console only
timerThe timer which shall be used by this logger.
lama::Logger::Logger ( const std::string &  id,
LogLevel::LogLevel  level,
LoggerWriteBehaviour::LoggerWriteBehaviour  writeBehaviour,
const std::string &  logFileName,
std::auto_ptr< Timer timer,
bool  ignoreRank = false 
)

Creates a logger with the specified properties.

This constructor creates a common logger with the specified properties. These properties are the write behavior and the log-level. No file name for a logfile is required.

Parameters:
levelThe loglevel of the logger. Messages with a loglevel greater than the level of the logger will be omitted. Instead of a common logger with the "noLogging" loglevel a NullLogger should be used.
writeBehaviourSpecifies, if the logger shall write its output to the console and a file or to the console only
logFileNameThe name of the logfile which shall be used by the logger. WARNING: If the users wants so use multiple loggers in different solvers this constructor should only be used once (for example with the top-level solver). The other solvers should than use the other constructor for the common logger.
timerThe timer which shall be used by this logger.

References lama::FileLogger::getFileLogger(), and lama::FileLogger::setLogFile().

lama::Logger::~Logger ( ) [virtual]

Destructor.


Member Function Documentation

virtual std::string lama::Logger::createPrefix ( ) [protected, pure virtual]

Template-Pattern Method - used by subclasses to create a prefix which will be added to each message.

Parameters:
messageThe message to be modified.

Implemented in lama::CommonLogger.

Referenced by logString().

Returns the log level of this logger.

Returns:
The log level of this.

References mLogLevel.

const std::string & lama::Logger::id ( ) const

Returns the id of this.

Returns:
the id of this.

References mId.

void lama::Logger::logMessage ( LogLevel::LogLevel  level,
const std::string &  message 
)

Logs a user specified message.

This method logs a user specified message (string)

Parameters:
levelThe loglevel of the message.
messageThe message to log.

References logString().

Referenced by logString().

Logs an empty line.

Parameters:
levelThe LogLevel at which the empty line shall be logged

References logString().

void lama::Logger::logResidual ( LogLevel::LogLevel  level,
const Solver solver,
const Norm norm,
const std::string  iterationPrefix = "" 
)

Logs the residual of the solver.

Parameters:
[in]LogLevelThe LogLevel at which the residual shall be logged.
[in]solverThe solver which supplies the residual
[in]normThe Norm used to calculate the residual
[in]iterationPrefixA Prefix to put in front of the generated log message (Default: "" )

References lama::Solver::getResidual(), logString(), and mLogLevel.

void lama::Logger::logString ( LogLevel::LogLevel  level,
const std::string &  message 
) [protected, virtual]

Performs a LogLevel check and logs the message depending on this.

Parameters:
[in]levelThe LogLevel to log the string at.
[in]messageThe string to be logged.

References mIgnoreRank, and mLogLevel.

Referenced by logMessage(), logNewLine(), logResidual(), logTime(), and logType().

void lama::Logger::logString ( const std::string &  message) [protected, virtual]
void lama::Logger::logTime ( const std::string &  timerId,
LogLevel::LogLevel  level,
const std::string &  message 
)

logs the elapsed time in combination with a user-specified message.

Logs the elapsed time since the internal timer got started, does not stop the timer. The caller may also specify an additional message. The time and message will be logged in the format [message] [time].

Parameters:
[in]timerIdThe ID of the timer whoms time shall be logged.
[in]levelThe loglevel of the message.
[in]messageThe message to log.

References LAMA_ASSERT_DEBUG, logString(), mLogLevel, and mTimer.

template<typename T >
void lama::Logger::logType ( LogLevel::LogLevel  level,
const std::string &  message,
arg 
)

logs a message followed by an custom type by using the << operator.

Example: Can be used to log the number of iterations made by an iterative solver.

Parameters:
[in]levelThe LogLevel
[in]messageThe message which shall be logged
[in]argThe The argument which shall be logged after the message. The << operator must be defined for it!

References logString(), and mLogLevel.

Sets the internal LogLevel.

Returns:

References mLogLevel.

void lama::Logger::startTimer ( const std::string &  timerId)

Starts an internal timer of the logger.

Starts the internal timer of the logger.

Parameters:
[in]timerIdThe ID of the timer which shall be started.

References LAMA_ASSERT_DEBUG, and mTimer.

void lama::Logger::stopAndResetTimer ( const std::string &  timerId)

Stops and resets an internal timer.

Stops and resets the internal timer.

Parameters:
[in]timerIdThe ID of the timer which shall be stopped and resetted.

References LAMA_ASSERT_DEBUG, and mTimer.

void lama::Logger::stopTimer ( const std::string &  timerId)

Stops an internal timer of the logger.

Does not reset it.

Stops an internal timer of the logger. Does not reset the timer. The caller may call startTimer() again and the timer will continue to measure the time, beginning with the amount of time it had measured, before the timer got stopped.

Parameters:
[in]timerIdThe ID of the timer which shall be stopped.

References LAMA_ASSERT_DEBUG, and mTimer.


Field Documentation

std::string lama::Logger::mId [protected]
bool lama::Logger::mIgnoreRank [private]

Referenced by logString().

std::auto_ptr<Timer> lama::Logger::mTimer [protected]

Timer used for timings.

Referenced by Logger(), logTime(), startTimer(), stopAndResetTimer(), and stopTimer().


The documentation for this class was generated from the following files: