|
ddt
0.1
|
#include <ddtLogger.hpp>
Public Member Functions | |
| DdtLogger (const std::string &loggerName) | |
| DdtLogger (const std::string &loggerName, char *applicationPath) | |
| virtual | ~DdtLogger () |
| void | logTrace (const std::string &logMsg) |
| void | logDebug (const std::string &logMsg) |
| void | logInfo (const std::string &logMsg) |
| void | logWarn (const std::string &logMsg) |
| void | logError (const std::string &logMsg) |
| void | logFatal (const std::string &logMsg) |
| void | configure (const std::string &module) |
| void | setLogLevel (const int logLevel) |
| void | write (const int severity, const std::string &message) |
Static Public Member Functions | |
| static void | writeToLogger (DdtLogger *logger, const int severity, const std::string &message) |
Static Public Attributes | |
| static const int | DDT_OFF = 6 |
| static const int | DDT_FATAL = 5 |
| static const int | DDT_ERROR = 4 |
| static const int | DDT_WARN = 3 |
| static const int | DDT_INFO = 2 |
| static const int | DDT_DEBUG = 1 |
| static const int | DDT_TRACE = 0 |
| static const int | DDT_ALL = 0 |
Class to wrap the usage of log4cplus as logging utility. The constructor is called with the logger name as argument. In this simple form, a basic logger is created that just provides a console appender.
In case that the application name is provided as second argument to the constructor, a logging properties file is searched. The file specification is built as follows: <environment variable DDT_LOGCONFIG_PATH>/log4cplus_<lower case version of the application name>.properties If the environment variable is not defined, or the properties file is not existing, a basic logger will be created that just provides a console appender.
The usage is as follows:
#include "ddt/ddtLogger.hpp" ... using namespace ddt;
DdtLogger logger(std::string("DdtDataBroker"), argv[0]); // The string "DdtDataBroker" is just an example for a logger name.
logger.setLogLevel(DdtLogger::DDT_INFO); logger.configure("DataBroker");
logger.write(DdtLogger::DDT_TRACE, "Trace message"); logger.write(DdtLogger::DDT_DEBUG, "Debug message"); logger.write(DdtLogger::DDT_INFO, "Info message"); logger.write(DdtLogger::DDT_WARN, "Warn message"); logger.write(DdtLogger::DDT_ERROR, "Error message"); logger.write(DdtLogger::DDT_FATAL, "Fatal message"); ...
With help of the configure method a module can be specified which is prepended to each log message.
| DdtLogger::DdtLogger | ( | const std::string & | loggerName | ) |
Constructor
In this form, it will only create a basic logger that provides a console appender.
Set up basic logger with a console appender.
Set default module and log level.
| DdtLogger::DdtLogger | ( | const std::string & | loggerName, |
| char * | applicationPath | ||
| ) |
Constructor
In this form, it will look for a configuration file.
The file name will be constructed as follows: <environment variable DDT_LOGCONFIG_PATH>/log4cplus_<lower case version of the application name>.properties
If the environment variable is not defined, or the properties file is not existing, a basic logger will be created that just provides a console appender.
Get application name from path.
Initialize logging.
Check existence of logging properties.
Configure logging. If properties file is not existing or not found, only a console appender will be available.
Set default module and log level.
|
virtual |
Destructor
| void DdtLogger::configure | ( | const std::string & | module | ) |
Set the module name that is prepended to the log message when using the write() method.
| void DdtLogger::logDebug | ( | const std::string & | logMsg | ) |
Log message with DEBUG log level.
| void DdtLogger::logError | ( | const std::string & | logMsg | ) |
Log message with ERROR log level.
| void DdtLogger::logFatal | ( | const std::string & | logMsg | ) |
Log message with FATAL log level.
| void DdtLogger::logInfo | ( | const std::string & | logMsg | ) |
Log message with INFO log level.
| void DdtLogger::logTrace | ( | const std::string & | logMsg | ) |
Log message with TRACE log level.
| void DdtLogger::logWarn | ( | const std::string & | logMsg | ) |
Log message with WARN log level.
| void DdtLogger::setLogLevel | ( | const int | logLevel | ) |
Set the log level. Afterwards only log messages with a log level equal to or higher than the provided one will be logged. The log level DDT_OFF will switch off the logging completely.
| void DdtLogger::write | ( | const int | severity, |
| const std::string & | message | ||
| ) |
Write log messages with the provided severity / log level. The module name that is set with help of the configure() method will be prepended to the message string.
|
static |
Static version of the logging functions for the various log levels. Allows to insert a logger as first parameter.
|
static |
Log level DDT_ALL. This is equivalent to the DDT_TRACE log level.
|
static |
Log level DDT_DEBUG.
|
static |
Log level DDT_ERROR.
|
static |
Log level DDT_FATAL.
|
static |
Log level DDT_INFO.
|
static |
Log levels defined as integer constants. Log level DDT_OFF. This can be used to switch off logging completely.
|
static |
Log level DDT_TRACE.
|
static |
Log level DDT_WARN.