A logger to log messages. More...
#include <Logger.h>
Public Member Functions | |
Logger (const string &type) | |
Creates a new logger of the given type (debug, info, warning, etc). | |
virtual | ~Logger () |
Destroys this logger. | |
void | addTopic (const string &topic) |
Adds the given topic to the list of topics managed by this logger. | |
bool | hasTopic (const string &topic) |
Returns true if messages of the given topic are logged by this logger. | |
virtual void | log (const string &topic, const string &msg) |
Logs a message given by its topic and its content. | |
void | logf (const char *topic, const char *fmt,...) |
Formatted logging for more usability. | |
virtual void | flush () |
Flushes the buffer of this logger, if any. | |
Static Public Attributes | |
static static_ptr< Logger > | DEBUG_LOGGER |
The logger for debug messages. | |
static static_ptr< Logger > | INFO_LOGGER |
The logger for information messages. | |
static static_ptr< Logger > | WARNING_LOGGER |
The logger for warning messages. | |
static static_ptr< Logger > | ERROR_LOGGER |
The logger for error messages. | |
Protected Attributes | |
const string | type |
The type of this logger (debug, info, warning, error, etc). | |
string | topics |
The topics handled by this logger, separated by semi-columns. | |
void * | mutex |
A mutex to access this logger from multiple threads. |
A logger to log messages.
Debug, info, warning and error messages must be logged to the static DEBUG_LOGGER, INFO_LOGGER, WARNING_LOGGER and ERROR_LOGGER. Each message has a topic. By default a logger logs all messages, whatever their topic, but it is possible to restrict logging to some topics only with addTopic.
ork::Logger::Logger | ( | const string & | type | ) |
Creates a new logger of the given type (debug, info, warning, etc).
virtual ork::Logger::~Logger | ( | ) | [virtual] |
Destroys this logger.
void ork::Logger::addTopic | ( | const string & | topic | ) |
Adds the given topic to the list of topics managed by this logger.
By default a logger logs all messages, whatever their topic. But if at least one topic is selected by this method, only messages whose topic has been selected by this method will be logged.
virtual void ork::Logger::flush | ( | ) | [virtual] |
Flushes the buffer of this logger, if any.
Reimplemented in ork::FileLogger.
bool ork::Logger::hasTopic | ( | const string & | topic | ) |
Returns true if messages of the given topic are logged by this logger.
virtual void ork::Logger::log | ( | const string & | topic, | |
const string & | msg | |||
) | [virtual] |
Logs a message given by its topic and its content.
The default implementation of this method sends the message to the standard error output stream cerr.
Reimplemented in ork::FileLogger.
void ork::Logger::logf | ( | const char * | topic, | |
const char * | fmt, | |||
... | ||||
) |
Formatted logging for more usability.
The problem is that Logger is not an ostream (or an ostringstream). I tried to derive ostream but it requires extra work. So here go C variadic functions. Must have a char * topic since std::string are not POD and this does not work with variable arguments list :| So it's really a compromise.
static_ptr<Logger> ork::Logger::DEBUG_LOGGER [static] |
The logger for debug messages.
static_ptr<Logger> ork::Logger::ERROR_LOGGER [static] |
The logger for error messages.
static_ptr<Logger> ork::Logger::INFO_LOGGER [static] |
The logger for information messages.
void* ork::Logger::mutex [protected] |
A mutex to access this logger from multiple threads.
string ork::Logger::topics [protected] |
The topics handled by this logger, separated by semi-columns.
An empty string means that all topics are handled.
const string ork::Logger::type [protected] |
The type of this logger (debug, info, warning, error, etc).
Reimplemented from ork::Object.
static_ptr<Logger> ork::Logger::WARNING_LOGGER [static] |
The logger for warning messages.