#include <source/toolbox/base/Logger.h>
Public Member Functions | |
void | logAbort (const std::string &message, const std::string &filename, const int line) |
void | logWarning (const std::string &message, const std::string &filename, const int line) |
void | logDebug (const std::string &message, const std::string &filename, const int line) |
void | setAbortAppender (tbox::Pointer< Appender > appender) |
void | setWarningAppender (tbox::Pointer< Appender > appender) |
void | setDebugAppender (tbox::Pointer< Appender > appender) |
void | setWarning (bool onoff) |
void | setDebug (bool onoff) |
Static Public Member Functions | |
static Logger * | getInstance () |
static void | free () |
Classes | |
class | Appender |
The logAbort, logWarning, and logDebug methods are used to log a message coming from a file and line.
Warning and Debug messages can be turned on/off using the setWarning and setDebug methods. Abort messages may not be turned off.
Applications may override the logging mechanism.The basic idea is the singleton Logger directs log messages to the appropriate Appender which is responsible for writing the log message. The Appender is the destination for the log message. Users may supply implementors of the Appender interface to log the messages to different I/O streams or elsewhere. In this way applications can redirect SAMRAI generated messages to that applications logging mechanism. Appenders may be provided for abort, warning, and/or debug messages. The same Appender may be used for all messages.
For example to log to a stream simply inherit from LoggerAppender and implement the logMesage method:
class StreamAppender : public tbox::Logger::Appender { public: StreamAppender(ostream *stream) { d_stream = stream; } void logMessage(const std::string &message, const std::string &filename, const int line) { (*d_stream) << "At :" << filename << " line :" << line << " message: " << message << std::endl; } private: ostream *d_stream; };
This Appender could be use to log warning message using: tbox::Pointer<tbox::Logger::Appender> appender = new ConsoleAppender() tbox::Logger.getInstance() -> setWarningAppender(appender);
Normally this would be done at the start of an application.
Logger * SAMRAI::tbox::Logger::getInstance | ( | ) | [static] |
Gets the instance of the singleton logger.
void SAMRAI::tbox::Logger::free | ( | ) | [static] |
Frees instance of the singleton logger.
NOTE: should be called by ShutdownRegistry only.
void SAMRAI::tbox::Logger::logAbort | ( | const std::string & | message, | |
const std::string & | filename, | |||
const int | line | |||
) |
Logs an abort message with file & location
void SAMRAI::tbox::Logger::logWarning | ( | const std::string & | message, | |
const std::string & | filename, | |||
const int | line | |||
) |
Logs warning message with file & location.
void SAMRAI::tbox::Logger::logDebug | ( | const std::string & | message, | |
const std::string & | filename, | |||
const int | line | |||
) |
Logs debug message with file & location.
void SAMRAI::tbox::Logger::setAbortAppender | ( | tbox::Pointer< Appender > | appender | ) |
Set the Appender for logging abort messages to an application specific class.
Default is to log to perr.
void SAMRAI::tbox::Logger::setWarningAppender | ( | tbox::Pointer< Appender > | appender | ) |
Set the Appender for logging warning messages to an application specific class.
Default is to log to plog.
void SAMRAI::tbox::Logger::setDebugAppender | ( | tbox::Pointer< Appender > | appender | ) |
Set the Appender for logging debug messages to an application specific class.
Default is to log to plog.
void SAMRAI::tbox::Logger::setWarning | ( | bool | onoff | ) |
Turn logging of warning messages on or off.
Default is on.
void SAMRAI::tbox::Logger::setDebug | ( | bool | onoff | ) |
Turn logging of debug messages on or off.
Default is off.