LAMA
|
A logger abstraction. More...
#include <Logger.hpp>
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< Timer > | mTimer |
Timer used for timings. | |
std::string | mId |
Private Attributes | |
LogLevel::LogLevel | mLogLevel |
LoggerWriteBehaviour::LoggerWriteBehaviour | mWriteBehaviour |
bool | mIgnoreRank |
A logger abstraction.
This class represents a logger abstraction. It defines common logger operations. Derived classes may use the createPrefix() method to customize messages.
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.
level | The 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. |
writeBehaviour | Specifies, 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.
level | The 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. |
writeBehaviour | Specifies, if the logger shall write its output to the console and a file or to the console only |
timer | The 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.
level | The 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. |
writeBehaviour | Specifies, if the logger shall write its output to the console and a file or to the console only |
logFileName | The 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. |
timer | The timer which shall be used by this logger. |
References lama::FileLogger::getFileLogger(), and lama::FileLogger::setLogFile().
lama::Logger::~Logger | ( | ) | [virtual] |
Destructor.
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.
message | The message to be modified. |
Implemented in lama::CommonLogger.
Referenced by logString().
LogLevel::LogLevel lama::Logger::getLogLevel | ( | ) | const |
const std::string & lama::Logger::id | ( | ) | const |
lama::Logger::LAMA_LOG_DECL_STATIC_LOGGER | ( | logger | ) | [protected] |
void lama::Logger::logMessage | ( | LogLevel::LogLevel | level, |
const std::string & | message | ||
) |
Logs a user specified message.
This method logs a user specified message (string)
level | The loglevel of the message. |
message | The message to log. |
References logString().
Referenced by logString().
void lama::Logger::logNewLine | ( | LogLevel::LogLevel | level | ) |
Logs an empty line.
level | The 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.
[in] | LogLevel | The LogLevel at which the residual shall be logged. |
[in] | solver | The solver which supplies the residual |
[in] | norm | The Norm used to calculate the residual |
[in] | iterationPrefix | A 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.
[in] | level | The LogLevel to log the string at. |
[in] | message | The 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] |
Logs the message.
DOES NOT perform a LogLevel check.
[in] | message | The message to be logged. |
References createPrefix(), lama::FileLogger::getFileLogger(), lama::FileLogger::logMessage(), logMessage(), mWriteBehaviour, lama::LoggerWriteBehaviour::toConsoleOnly, lama::LoggerWriteBehaviour::toFileAndConsole, and lama::LoggerWriteBehaviour::toFileOnly.
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].
[in] | timerId | The ID of the timer whoms time shall be logged. |
[in] | level | The loglevel of the message. |
[in] | message | The message to log. |
References LAMA_ASSERT_DEBUG, logString(), mLogLevel, and mTimer.
void lama::Logger::logType | ( | LogLevel::LogLevel | level, |
const std::string & | message, | ||
T | 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.
[in] | level | The LogLevel |
[in] | message | The message which shall be logged |
[in] | arg | The The argument which shall be logged after the message. The << operator must be defined for it! |
References logString(), and mLogLevel.
void lama::Logger::setLogLevel | ( | LogLevel::LogLevel | level | ) |
void lama::Logger::startTimer | ( | const std::string & | timerId | ) |
Starts an internal timer of the logger.
Starts the internal timer of the logger.
[in] | timerId | The 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.
[in] | timerId | The 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.
[in] | timerId | The ID of the timer which shall be stopped. |
References LAMA_ASSERT_DEBUG, and mTimer.
std::string lama::Logger::mId [protected] |
Referenced by lama::CommonLogger::createPrefix(), and id().
bool lama::Logger::mIgnoreRank [private] |
Referenced by logString().
LogLevel::LogLevel lama::Logger::mLogLevel [private] |
Referenced by getLogLevel(), logResidual(), logString(), logTime(), logType(), and setLogLevel().
std::auto_ptr<Timer> lama::Logger::mTimer [protected] |
Timer used for timings.
Referenced by Logger(), logTime(), startTimer(), stopAndResetTimer(), and stopTimer().
Referenced by logString().